What is Python's __dunder__ (magic) methods?
Answer
Python's dunder (double underscore) methods enable operator overloading and customization of built-in behaviours. Numeric: __add__ (+), __sub__ (-), __mul__ (*), __truediv__ (/), __floordiv__ (//), __mod__ (%), __pow__ (**), plus reflected (__radd__) and in-place (__iadd__) versions. Comparison: __eq__, __ne__, __lt__, __gt__, __le__, __ge__. Container: __len__, __getitem__, __setitem__, __delitem__, __contains__, __iter__, __next__. Context manager: __enter__, __exit__. Callable: __call__ — makes instances callable. Attribute: __getattr__ (called when attribute not found), __getattribute__ (called for every access). Hash: __hash__ (required for dict keys and set elements).
Previous
What is Python's memory management and garbage collection?
Next
What is Python's type system and static typing with mypy?