Python Advanced Quiz

1. What is a decorator in Python?

a) A loop construct
b) A function that modifies another function
c) A type of variable
d) A class method

2. What does `yield` do in a function?

a) Terminates the function
b) Returns a generator object
c) Prints output
d) Raises an exception

3. True or False: A context manager can be used with the `with` statement.

a) True
b) False

4. What is the output of `class A: pass; A.__class__`?

a) A
b) type
c) None
d) Error

5. What does `@classmethod` do?

a) Makes a method static
b) Passes the class as the first argument
c) Prevents method overriding
d) Creates a property

6. What is the purpose of `__slots__` in a class?

a) Defines instance methods
b) Reduces memory usage
c) Enables inheritance
d) Creates private attributes

7. What is the output of `[x for x in (1, 2, 3) if x > 1][-1]`?

a) 1
b) 2
c) 3
d) Error

8. True or False: Python's garbage collector uses reference counting.

a) True
b) False

9. What does `functools.partial` do?

a) Creates a new function with preset arguments
b) Splits a function into parts
c) Optimizes function execution
d) Defines a generator

10. What happens if `__init__` is not defined in a class?

a) The class cannot be instantiated
b) The parent class's `__init__` is used
c) An error is raised
d) The instance has no attributes