Python MCQ
Test your Python knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.
Which of the following is used to print output in Python?
2What is the correct way to declare a variable in Python?
3What data type is the result of 7 / 2 in Python 3?
4Which keyword is used to define a function in Python?
5What is the output of: type([1, 2, 3])?
6How do you write a comment in Python?
7What does the len() function return?
8Which of the following creates a tuple in Python?
9What is the correct way to start an if statement?
10What does PEP 8 define?
11What is the result of: "Python"[1:4]?
12Which keyword exits a loop in Python?
13What is a dictionary in Python?
14How do you import a module in Python?
15What is a list comprehension in Python?
16What is the output of: bool(0)?
17Which method adds an element to the end of a list?
18What does the range(5) function produce?
19What is a lambda function in Python?
20Which operator checks if two variables refer to the same object?
21What does the pass statement do?
22How do you handle exceptions in Python?
23What is the Python keyword for "not equal to"?
24What is the output of: 2 ** 3 in Python?
25Which built-in function converts a string to an integer?
26What does the in operator do with a list?
27What is the difference between a list and a tuple?
28What does the strip() method do to a string?
29How do you define a class in Python?
30What does __init__ do in a Python class?
31What is the first parameter of an instance method conventionally called?
32What does global keyword do in Python?
33What is a set in Python?
34Which Python method returns all keys of a dictionary?
35What is the output of: print(type(None))?
36What does the continue keyword do in a loop?
37Which of the following is an immutable data type in Python?
38How do you open a file for reading in Python?
39What is the purpose of the __str__ method?
40What does enumerate() do?
What is a generator in Python?
2What is the difference between @staticmethod and @classmethod?
3What does the *args parameter syntax allow?
4What is a decorator in Python?
5What is the purpose of __slots__?
6What is the Global Interpreter Lock (GIL)?
7What does functools.lru_cache do?
8What is the difference between deep copy and shallow copy?
9How does Python implement multiple inheritance?
10What is a context manager?
11What does yield from do in a generator?
12What is the difference between __repr__ and __str__?
13What is a Python metaclass?
14What does the @property decorator do?
15What is monkey patching?
16What is the purpose of __all__ in a Python module?
17What is the difference between is and == for small integers?
18What is asyncio used for?
19What does collections.defaultdict provide?
20What is a descriptor in Python?
21What is the difference between multiprocessing and threading in Python?
22What does collections.Counter do?
23What is the walrus operator := ?
24What is a frozenset?
25What is the purpose of __enter__ and __exit__ methods?
26What does itertools.chain do?
27What does zip() do in Python?
28What is a namedtuple?
29What does the nonlocal keyword do?
30What is the purpose of __slots__ in Python classes?
31What does functools.partial do?
32What is the threading module's Lock versus RLock?
33What is __getattr__ vs __getattribute__?
34What is a Python abstract property?
35What is the purpose of contextlib.contextmanager?
36What is asyncio.gather() used for?
37What is the difference between Process and Thread in Python's multiprocessing vs threading?
38What is Python's __new__ vs __init__?
39What is the difference between deepcopy and pickle for copying objects?
40What is Python's __class_getitem__ for?
How does Python's garbage collector handle reference cycles?
2What is the descriptor protocol and how does it relate to @property?
3What is the __mro__ attribute and how is it computed?
4What is a coroutine in Python and how does it differ from a generator?
5What does __new__ do and when would you override it?
6What are Python's "magic methods" and what is their purpose?
7How does Python's import system find and load modules?
8What is a Python abstract base class (ABC) used for?
9What does sys.setrecursionlimit do and what is its trade-off?
10What is a Python dataclass (@dataclass decorator) and what does it generate?
11What is Python's object model's lookup chain for an attribute?
12What is the CPython GIL's switch interval?
13What is Python's frame object and how does the CPython eval loop use it?
14What is the difference between __import__ and importlib?
15What is the free-threaded CPython (PEP 703, Python 3.13)?
16What is a Python traced function and how does sys.settrace work?
17What is Python's "small integer" optimization?
18What is Python's __reduce__ method used for?
19What is the Python weak reference module and when is it used?
20What is a Python coroutine protocol (PEP 342)?
21What is the bytearray type and when would you use it over bytes?