Question 51
In Python classes, what is the purpose of the '__str__(self)' magic method?
__str__ is called by print(obj) and str(obj) to display a friendly string representation.
In Python classes, what is the purpose of the '__str__(self)' magic method?
__str__ is called by print(obj) and str(obj) to display a friendly string representation.
In Python classes, what is the purpose of the '__repr__(self)' magic method?
__repr__ aims to be unambiguous and ideally a valid Python expression to recreate the object.
In Python, what magic method is overloaded to define behavior for the equality comparison operator '==' between custom objects?
Defining __eq__(self, other) customizes how obj1 == obj2 evaluates for custom class instances.
Which Python magic method enables instances of a custom class to be called like functions (e.g., obj(arg1))?
Implementing __call__ allows class instances to be callable like standard functions.
In Python, what is the '@property' decorator used for?
@property turns a method into a read-only property attribute.