Python Quiz

1 / 25

Which of the following is the correct way to open a file in Python for writing, overwriting its content if it already exists?

2 / 25

What is a docstring in Python?

3 / 25

Which of the following is the correct syntax for a `for` loop that iterates over a list named `my_list`?

4 / 25

Which of these is the correct way to handle exceptions in Python?

5 / 25

In Python, which of the following is a key difference between a list and a tuple?

6 / 25

What is the output of `len('Hello World'.split())`?

7 / 25

Which of the following is a valid way to create a dictionary in Python?

8 / 25

Which of the following is NOT a built-in module in the Python Standard Library?

9 / 25

What does the `pass` statement do in Python?

10 / 25

What is the output of the following code snippet?

`print(type([]) is list)`

11 / 25

What is the key feature that makes a dictionary different from a list?

12 / 25

Which of the following is a correct way to unpack a tuple `t = (1, 2, 3)` into three variables?

13 / 25

Which of the following data types is mutable?

14 / 25

Which of the following statements about global variables in Python is true?

15 / 25

What is the primary purpose of the `__init__` method in a Python class?

16 / 25

What is a decorator in Python?

17 / 25

What is a virtual environment in Python?

18 / 25

What is the purpose of the `yield` keyword in a function?

19 / 25

What is the purpose of the `self` parameter in a class method?

20 / 25

What does a negative index in a Python list do?

21 / 25

What is the purpose of the `super()` function in Python?

22 / 25

Which of the following is an example of a built-in Python function?

23 / 25

What is a lambda function in Python?

24 / 25

What is the result of `10 // 3` in Python?

25 / 25

What does a generator function use to produce a series of values lazily?

Your score is



Overview:

Think you know Python? Take our Python Quiz to challenge yourself with coding questions on syntax, loops, functions, and more. Whether you’re a beginner or preparing for interviews, this quiz is the perfect way to sharpen your programming skills!