🐍

Python MCQ

Test your Python knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.

101 Questions 40 Beginner 40 Intermediate 21 Advanced
1

Which of the following is used to print output in Python?

2

What is the correct way to declare a variable in Python?

3

What data type is the result of 7 / 2 in Python 3?

4

Which keyword is used to define a function in Python?

5

What is the output of: type([1, 2, 3])?

6

How do you write a comment in Python?

7

What does the len() function return?

8

Which of the following creates a tuple in Python?

9

What is the correct way to start an if statement?

10

What does PEP 8 define?

11

What is the result of: "Python"[1:4]?

12

Which keyword exits a loop in Python?

13

What is a dictionary in Python?

14

How do you import a module in Python?

15

What is a list comprehension in Python?

16

What is the output of: bool(0)?

17

Which method adds an element to the end of a list?

18

What does the range(5) function produce?

19

What is a lambda function in Python?

20

Which operator checks if two variables refer to the same object?

21

What does the pass statement do?

22

How do you handle exceptions in Python?

23

What is the Python keyword for "not equal to"?

24

What is the output of: 2 ** 3 in Python?

25

Which built-in function converts a string to an integer?

26

What does the in operator do with a list?

27

What is the difference between a list and a tuple?

28

What does the strip() method do to a string?

29

How do you define a class in Python?

30

What does __init__ do in a Python class?

31

What is the first parameter of an instance method conventionally called?

32

What does global keyword do in Python?

33

What is a set in Python?

34

Which Python method returns all keys of a dictionary?

35

What is the output of: print(type(None))?

36

What does the continue keyword do in a loop?

37

Which of the following is an immutable data type in Python?

38

How do you open a file for reading in Python?

39

What is the purpose of the __str__ method?

40

What does enumerate() do?

1

What is a generator in Python?

2

What is the difference between @staticmethod and @classmethod?

3

What does the *args parameter syntax allow?

4

What is a decorator in Python?

5

What is the purpose of __slots__?

6

What is the Global Interpreter Lock (GIL)?

7

What does functools.lru_cache do?

8

What is the difference between deep copy and shallow copy?

9

How does Python implement multiple inheritance?

10

What is a context manager?

11

What does yield from do in a generator?

12

What is the difference between __repr__ and __str__?

13

What is a Python metaclass?

14

What does the @property decorator do?

15

What is monkey patching?

16

What is the purpose of __all__ in a Python module?

17

What is the difference between is and == for small integers?

18

What is asyncio used for?

19

What does collections.defaultdict provide?

20

What is a descriptor in Python?

21

What is the difference between multiprocessing and threading in Python?

22

What does collections.Counter do?

23

What is the walrus operator := ?

24

What is a frozenset?

25

What is the purpose of __enter__ and __exit__ methods?

26

What does itertools.chain do?

27

What does zip() do in Python?

28

What is a namedtuple?

29

What does the nonlocal keyword do?

30

What is the purpose of __slots__ in Python classes?

31

What does functools.partial do?

32

What is the threading module's Lock versus RLock?

33

What is __getattr__ vs __getattribute__?

34

What is a Python abstract property?

35

What is the purpose of contextlib.contextmanager?

36

What is asyncio.gather() used for?

37

What is the difference between Process and Thread in Python's multiprocessing vs threading?

38

What is Python's __new__ vs __init__?

39

What is the difference between deepcopy and pickle for copying objects?

40

What is Python's __class_getitem__ for?