Defintion
Special methods that are represented in python with double underscores on either side
examples:
__init__()
__lt__Use cases
- Construction and initialization
__new__(cls, [...)creates new instance of class, used rarely, under the hood stuff__init__initializer for the class. It gets passed whatever the primary constructor was called with__del__destructor of the object, almost never used so use with caution
- Comparison
__cmp__(self, other)implements comparison for all the operators. Usually want to implement them one by one__eq__(self, other)equality__ne__(self, other)inequality__lt__(self, other)less-than__gt__(self, other)greater-than__le__(self, other)less-than-or-equal-to__ge__(self, other)greater-than-or-equal-to
- Numeric
- …
- Representation
__str__(self)defines behavior for when str(class) is called