ExamVeda
Login
Home
11
How is a decorator applied to a class method in Python?
Discuss
Answer & Solution
Answer: Option B
Solution:
A decorator is applied to a class method using the @decorator syntax above the method definition.
12
What is the purpose of the property decorator in Python?
Discuss
Answer & Solution
Answer: Option C
Solution:
The property decorator is used to define a getter method for a class attribute.
13
What is the role of the @staticmethod decorator in Python?
Discuss
Answer & Solution
Answer: Option B
Solution:
The @staticmethod decorator allows a method to be called without creating an instance of the class.
14
How does the @classmethod decorator differ from @staticmethod?
Discuss
Answer & Solution
Answer: Option C
Solution:
The @classmethod decorator can access class attributes, while @staticmethod cannot.
15
What is the purpose of the @property decorator in Python?
Discuss
Answer & Solution
Answer: Option B
Solution:
The @property decorator is used to define a getter method for a class attribute, allowing access as a property.
16
What is the purpose of the @classmethod decorator in Python?
Discuss
Answer & Solution
Answer: Option A
Solution:
The @classmethod decorator is used to define a method that operates on the class and not just instances.
17
How is the @classmethod decorator applied to a method in a class?
Discuss
Answer & Solution
Answer: Option B
Solution:
The @classmethod decorator is applied above the method definition using the @classmethod syntax.
18
What is the purpose of the @abstractmethod decorator in Python?
Discuss
Answer & Solution
Answer: Option C
Solution:
The @abstractmethod decorator indicates that a method must be overridden in subclasses.
19
How do you create a custom decorator in Python?
Discuss
Answer & Solution
Answer: Option D
Solution:
You create a custom decorator by defining a function and using the @decorator_name syntax.
20
What is the purpose of the functools.partial function in decorators?
Discuss
Answer & Solution
Answer: Option A
Solution:
The functools.partial function is used to create a new function with some arguments pre-filled.