Python Programming - Decorators - Discussion
Discussion Forum : Decorators - General Questions (Q.No. 20)
20.
What is the primary purpose of the
@functools.total_ordering
decorator?
Answer: Option
Explanation:
The
@functools.total_ordering
decorator is used to automatically generate rich comparison methods (e.g., __eq__
, __lt__
) based on a minimal set of comparison methods provided in the class.
@functools.total_ordering
class MyClass:
def __init__(self, value):
self.value = value
def __eq__(self, other):
return self.value == other.value
def __lt__(self, other):
return self.value < other.value
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers