How Well Do You Understand Python?
Put your Python knowledge to the test with this quiz and see how many correct answers you can get out of 20!
Question 1 of 20How Well Do You Understand Python?
All 20 questions
- Which of the following is a characteristic of Python's garbage collection mechanism?Manual memory management · Reference counting and a cyclic garbage collector · Only manual memory deallocation · No garbage collection
- Which feature is NOT inherited by Python from the ABC language?Built-in tuple types · Structure by indentation · Strong typing without variable declarations · Object-oriented programming
- What is 'Timsort' in Python?A type of variable · A sorting algorithm · A data structure · A built-in function
- In Python, which statement is used to handle exceptions?try/except · catch/throw · validate/rescue · attempt/handle
- Which of the following is NOT an immutable sequence type in Python?tuple · string · list · bytes
- What does the 'yield' keyword do in Python?Exits a function and returns a value · Causes the function to return a generator · Creates a lambda function · Defines a new variable
- In Python, what does the '*' operator do when used in a function definition?Unpacks a list or tuple · Creates a pointer · Raises an error · Multiplies values
- What does the `enumerate()` function do when applied to a list?Counts the elements in the list · Returns an iterator that yields pairs of index and value · Sorts the list in-place · Concatenates the list elements into a string
- Which Python feature allows for the creation of one-liner loops and conditionals inside a list declaration?Lambda functions · List comprehensions · Generator expressions · Map functions
- Which built-in function can be used to display the documentation of a function object?manual() · doc() · info() · help()
- What is the primary function of the `__init__` method in a class?To initialize the class object · To destroy the class object · To define class-level variables · To create private variables
- What does `self` refer to in a class method?The class itself · A global variable · The instance calling the method · None of the above
- Which Python feature allows a quick check if an object supports a protocol via try/except without using `isinstance` or `hasattr`?Duck Typing · Strict Typing · Static Typing · Dynamic Typing
- What is the difference between `list.sort()` and `sorted(list)`?list.sort() sorts the list in place, while sorted(list) returns a new sorted list. · list.sort() returns a new sorted list, while sorted(list) sorts the list in place. · There is no difference · list.sort() can sort lists of mixed data types, while sorted(list) cannot.
- Which method is used to replace parts of a string in Python?replace() · substitute() · substring() · swap()
- What does the `defaultdict` class from the collections module do?Automatically handles missing keys by inserting a default value · Generates a dictionary from a list · Removes duplicate keys · Sorts dictionary keys
- What is a primary advantage of using Python's `deque` over a list for queue operations?More consistent syntax · Efficient append and pop operations from both ends · Increased security · Less memory usage
- Which of the following is NOT a built-in sequence type in Python?string · list · tuple · map
- What is a Python decorator typically used for?To modify or extend the behavior of a function or method · To define a new class · To execute a function in parallel · To import modules
- What is the primary purpose of the `with` statement in Python?To create a loop · To open files and handle exceptions · To define a class · To handle context management





