PRACTICE • LEARN • GROW
Module 12: Advanced Python - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 12: Advanced Python - Final Quiz Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What will be the output of the following list comprehension?
evens = [x * 2 for x in range(5) if x % 2 == 0]
print(evens)
A.
[0, 2, 4]
B.
[0, 4, 8]
C.
[4, 8]
D.
[0, 2, 4, 6, 8]
Explanation & Key
Correct Answer:
2
What is the output of the following dictionary comprehension?
d = {x: x**2 for x in (1, 2, 3)}
print(d[3])
A.
3
B.
9
C.
6
D.
KeyError
Explanation & Key
Correct Answer:
3
What is the key difference between a normal function and a Generator Function in Python?
A.
Generator functions run faster in C hardware
B.
A generator function uses the 'yield' keyword instead of 'return', returning a lazy iterator that produces values on demand one at a time
C.
A generator function can only be executed in a multi-threaded process
D.
A generator function cannot take arguments
Explanation & Key
Correct Answer:
4
What will happen when attempting to consume an already-exhausted generator a second time?
def gen():
yield 1
yield 2
g = gen()
list1 = list(g)
list2 = list(g)
print(list1, list2)
A.
[1, 2] [1, 2]
B.
[1, 2] []
C.
[1, 2] [None]
D.
Raises StopIteration
Explanation & Key
Correct Answer:
5
What is a Decorator in Python?
A.
A graphical UI styling tool in Tkinter
B.
A function that takes another function as an argument, extends its behavior, and returns a callable wrapper without modifying the original source code
C.
A comment block preceding a function
D.
A class constructor
Explanation & Key
Correct Answer:
6
What will be printed when executing this minimal decorator example?
def my_dec(func):
def wrapper():
print("Start")
func()
print("End")
return wrapper
@my_dec
def greet():
print("Hello")
greet()
A.
Hello
B.
Start\nHello\nEnd
C.
Start\nEnd\nHello
D.
TypeError
Explanation & Key
Correct Answer:
7
Which built-in decorator from the
functools module provides automatic memoization / caching for expensive function calls?
A.
@functools.memoize
B.
@functools.lru_cache
C.
@functools.cache_all
D.
@functools.speedup
Explanation & Key
Correct Answer:
8
Why should developers apply
@functools.wraps(func) inside custom decorator wrappers?
A.
To prevent recursion bugs
B.
To preserve the original function's metadata (such as __name__, __doc__, and signature) which would otherwise be overwritten by the wrapper
C.
To make the decorator thread-safe
D.
To force the function to return integers only
Explanation & Key
Correct Answer:
9
What is the memory advantage of a Generator Expression
(x*x for x in range(1000000)) over a List Comprehension [x*x for x in range(1000000)]?
A.
The generator expression compiles to native C code
B.
The generator expression computes items on the fly using negligible memory, whereas the list comprehension allocates all 1,000,000 numbers in RAM immediately
C.
There is no difference in memory usage
D.
The list comprehension is garbage collected immediately
Explanation & Key
Correct Answer:
10
Which Python standard library module provides specialized container datatypes like
defaultdict, Counter, and deque?
A.
itertools
B.
collections
C.
dataclasses
D.
containers
Explanation & Key
Correct Answer:
11
What exception is automatically raised by an iterator's
__next__() method when there are no further elements to produce?
A.
IndexError
B.
StopIteration
C.
GeneratorExit
D.
EOFError
Explanation & Key
Correct Answer:
12
What built-in module provides object-oriented, cross-platform filesystem path manipulations in modern Python?
A.
os.path only
B.
pathlib
C.
sys.files
D.
shutil
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong