Play this programming quiz on Python fundamentals — 15 medium-level questions and answers.
1. Which symbol is used for comments in Python?
💡 The '#' symbol is used to write single-line comments in Python.
2. What does the 'try/except' block do in Python?
💡 The 'try/except' block allows a program to handle errors gracefully without crashing.
3. What does len() do in Python?
💡 The len() function returns the number of items in an object, such as a string or list.
4. What data type is used to store True or False in Python?
💡 The 'bool' data type stores Boolean values, True or False, in Python.
5. What does 'None' represent in Python?
💡 'None' is a special value in Python representing the absence of a value or a null value.
6. What is a Python dictionary used for?
💡 A Python dictionary stores data as key-value pairs, allowing fast lookup by key.
7. What is the correct way to create a list in Python?
💡 Lists in Python are created using square brackets, like [1, 2, 3].
8. What is 'self' used for in Python class methods?
💡 'self' refers to the current instance of a class and is used to access its attributes and methods.
9. What keyword is used to create a class in Python?
💡 The 'class' keyword is used to define a new class in Python.
10. What does 'import' do in Python?
💡 The 'import' statement brings in code from external modules or libraries for use in a program.
11. Which keyword is used to define a function in Python?
💡 The 'def' keyword is used to define a function in Python.
12. What is the correct file extension for Python files?
💡 Python files are saved with the .py file extension.
13. What does 'for i in range(5):' do?
💡 range(5) generates numbers 0 through 4, so this loop executes 5 times.
14. What is the output of print(2 + 3) in Python?
💡 Python evaluates 2 + 3 as arithmetic addition, printing the result, 5.
15. Which method adds an item to the end of a list in Python?
💡 The append() method adds a single item to the end of a Python list.