Loading

Quipoin Menu

Learn • Practice • Grow

Direction: Choose the correct option

Q1.

What is a decorator in Python?
A. A design pattern
B. A class method
C. A built-in function
D. A function that takes another function and extends its behavior
Direction: Choose the correct option

Q2.

How do you apply a decorator `@my_decorator` to a function?
A. Use `func = my_decorator(func)`
B. Call `my_decorator(func)`
C. Both A and C
D. Place `@my_decorator` above the function definition
Direction: Choose the correct option

Q3.

What is the output of a decorator that returns a wrapper?
A. The decorator runs once at definition
B. All of the above
C. The original function is replaced
D. The wrapper function is executed when the decorated function is called
Direction: Choose the correct option

Q4.

How do you pass arguments to a decorator?
A. Use `@decorator(arg)`
B. Use `@decorator(arg)`
C. Both A and B
D. Create a decorator factory that returns a decorator
Direction: Choose the correct option

Q5.

What is the purpose of `functools.wraps`?
A. Preserves the original function's metadata
B. Adds attributes
C. Wraps the function
Direction: Choose the correct option

Q6.

Can decorators be applied to classes?
A. Yes, but only with metaclasses
B. Yes, but only with `@classmethod`
C. No, only functions
D. Yes, class decorators modify classes
Direction: Choose the correct option

Q7.

What is a common use case for decorators?
A. Timing functions
B. All of the above
C. Logging
D. Access control
Direction: Choose the correct option

Q8.

What is the output of `@deco; def f(): pass` if `deco` just returns the function?
A. Error
B. Function f is unchanged
D. Function f is replaced
Direction: Choose the correct option

Q9.

How do you define a decorator that takes an optional argument?
A. Use a decorator factory with a default argument
B. Both A and C
C. Use `@deco()`
D. Use `@deco` without parentheses
Direction: Choose the correct option

Q10.

What does `@staticmethod` do?
A. Defines a static method
B. Defines a decorator
C. Defines a class method
D. Defines a property