📚 What's Included
- 30+ interactive multiple-choice questions
- Instant feedback with detailed explanations
- Code-based questions to test practical understanding
- Progressive difficulty from beginner to advanced
- Track your progress and score
- Comprehensive coverage of Python fundamentals
30
Total Questions
0
Answered
0
Correct
0%
Score
Python Fundamentals Quiz
1. What is the output of: print(type([]))
Explanation: The empty brackets [] create an empty list. The type() function returns <class 'list'> for list objects.
2. Which of the following is NOT a valid Python variable name?
Explanation: Variable names cannot start with a number. "2fast" is invalid, while the others follow Python naming conventions.
3. What does the following code output?
print(10 // 3)
Explanation: The // operator performs floor division, which returns the integer quotient without the remainder. 10 // 3 = 3.
4. Which data type is immutable in Python?
Explanation: Tuples are immutable, meaning their elements cannot be changed after creation. Lists, dictionaries, and sets are mutable.
5. What is the output of: len("Hello\nWorld")
Explanation: \n is a single newline character. "Hello\nWorld" has 5 + 1 + 5 = 11 characters total.
6. What does the following code return?
[1, 2, 3] + [4, 5]
Explanation: The + operator concatenates lists, combining all elements into a single list: [1, 2, 3, 4, 5].
7. Which keyword is used to define a function in Python?
Explanation: Python uses the "def" keyword to define functions: def my_function():
8. What is the output of: bool("")
Explanation: An empty string is falsy in Python, so bool("") returns False. Non-empty strings are truthy.
9. What does the following code output?
x = [1, 2, 3]
y = x
y.append(4)
print(len(x))
Explanation: y = x creates a reference to the same list, not a copy. When y is modified, x is also affected. len(x) = 4.
10. Which method removes and returns the last element of a list?
Explanation: The pop() method removes and returns the last element. pop(index) can remove at a specific index.
Data Structures & OOP Quiz
11. What is the correct way to create a dictionary?
Explanation: Empty curly braces {} create an empty dictionary. [] creates a list, () creates a tuple.
12. What does the following list comprehension produce?
[x**2 for x in range(5) if x % 2 == 0]
Explanation: This filters even numbers (0, 2, 4) and squares them: 0²=0, 2²=4, 4²=16. Result: [0, 4, 16].
13. What is the purpose of the __init__ method in a class?
Explanation: __init__ is the constructor/initializer method that runs when a new object is created.
14. What does the "self" parameter represent in a class method?
Explanation: "self" refers to the instance of the class, allowing access to instance variables and methods.
15. What is the output of: {1, 2, 3} & {2, 3, 4}
Explanation: The & operator performs set intersection, returning common elements: {2, 3}.
16. What does dict.get('key', 'default') do if 'key' doesn't exist?
Explanation: The get() method returns the default value when the key doesn't exist, avoiding KeyError.
17. Which of these is NOT an OOP principle?
Explanation: The four OOP principles are: Encapsulation, Inheritance, Polymorphism, and Abstraction. Compilation is not an OOP principle.
18. What is the output of: "Python"[1:4]
Explanation: String slicing [1:4] extracts characters from index 1 to 3 (not including 4): "yth".
19. What does the zip() function do?
Explanation: zip() combines multiple iterables element-by-element into tuples: zip([1,2], ['a','b']) → [(1,'a'), (2,'b')].
20. What is a lambda function?
Explanation: Lambda functions are anonymous (unnamed) functions defined with the lambda keyword: lambda x: x * 2.
Advanced Concepts Quiz
21. What is a decorator in Python?
Explanation: Decorators are functions that modify the behavior of other functions using the @decorator syntax.
22. What does *args allow in a function?
Explanation: *args allows a function to accept any number of positional arguments as a tuple.
23. What is the difference between 'is' and '=='?
Explanation: 'is' checks if two variables refer to the same object (identity), while '==' checks if values are equal.
24. What does yield do in a function?
Explanation: yield creates a generator, returning values one at a time while preserving function state between calls.
25. What is a context manager?
Explanation: Context managers (used with 'with' statement) handle resource setup and cleanup automatically, like file operations.
26. What is the GIL in Python?
Explanation: GIL (Global Interpreter Lock) is a mutex that prevents multiple threads from executing Python bytecode simultaneously.
27. What does the enumerate() function return?
Explanation: enumerate() returns an iterator of tuples containing index and value: enumerate(['a','b']) → [(0,'a'), (1,'b')].
28. What is list slicing [::−1] used for?
Explanation: The slice [::−1] reverses a list by stepping backward through all elements.
29. What is the purpose of __str__ method?
Explanation: __str__ defines the user-friendly string representation of an object, used by print() and str().
30. What does the pass statement do?
Explanation: pass is a null statement that does nothing, used as a placeholder in empty code blocks.
🎉 Quiz Complete! Check your results above. Review the explanations for any questions you missed to reinforce your understanding.
💡 Study Tips:
- Review questions you got wrong and understand why
- Practice coding the concepts you're unsure about
- Retake the quiz to track improvement
- Combine this with hands-on coding practice
- Check the Python documentation for deeper understanding