Test your Python knowledge with functions, OOP and data structures!
1. What does the "pass" statement do in Python?
💡 "pass" is a null statement used as a placeholder where code is required syntactically but nothing needs to happen.
2. What is a dictionary in Python?
💡 A dictionary stores data as key-value pairs: {"name": "Ali", "age": 25}.
3. What does "import" do in Python?
💡 import loads external modules: "import math" gives access to math functions like math.sqrt().
4. What is the output of: print(2 ** 8)?
💡 ** is the exponentiation operator. 2 ** 8 = 2⁸ = 256.
5. What does "list comprehension" do in Python?
💡 List comprehension creates a new list: [x*2 for x in range(5)] → [0, 2, 4, 6, 8].
6. What does the "global" keyword do in Python?
💡 The "global" keyword inside a function allows it to modify a variable defined in the global scope.
7. What is a Python decorator?
💡 A decorator is a function that wraps another function to modify or extend its behavior using @decorator syntax.
8. What is a lambda function in Python?
💡 A lambda is a small anonymous function: lambda x: x + 1. It can have any number of arguments but one expression.
9. What does the "self" parameter in a Python class method refer to?
💡 "self" refers to the current object instance, allowing access to its attributes and methods.
10. What is the purpose of "__init__" in a Python class?
💡 __init__ is the constructor method called automatically when a new object is created from a class.
11. What is the difference between a list and a tuple in Python?
💡 Lists [] can be changed after creation (mutable). Tuples () cannot be changed (immutable).
12. What is the output of: print("Python"[0])?
💡 String indexing starts at 0. "Python"[0] is the first character: "P".
13. What is the output of: print(type([]))?
💡 An empty [] is a list in Python. type([]) returns <class "list">.
14. Which method adds an item to the end of a list?
💡 list.append(item) adds an item to the end of the list.
15. What does "try-except" do in Python?
💡 try-except catches and handles errors so the program does not crash when an exception occurs.