Python Programming - Classes
Exercise : Classes - General Questions
- Classes - General Questions
11.
What is the purpose of the
@property decorator?
Answer: Option
Explanation:
The
@property decorator is used to define a getter method for a class attribute. It allows the method to be accessed like an attribute without using parentheses.
12.
In Python, what is the purpose of the
__slots__ attribute in a class?
Answer: Option
Explanation:
The
__slots__ attribute in a class is used to explicitly declare a list of allowed attributes for instances of the class. It can help in saving memory by preventing the creation of additional instance attributes.
13.
What is the purpose of the
@abstractmethod decorator?
Answer: Option
Explanation:
The
@abstractmethod decorator is used to define abstract methods in an abstract class. Any concrete subclass must implement these abstract methods.
14.
What is the purpose of the
isinstance() function?
Answer: Option
Explanation:
The
isinstance() function is used to check if a variable is an instance of a specified class or a tuple of classes. It returns True if the object is an instance of any of the given classes.
15.
What is the primary purpose of the
__doc__ attribute?
Answer: Option
Explanation:
The
__doc__ attribute in Python is used to access the documentation string (docstring) associated with a module, class, or function. It provides information about the purpose and usage of the code.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers