Skip to main content

What are Python magic or dunder methods?

Junior Python
Quick Answer Dunder (double underscore) methods are special methods that Python calls implicitly. __init__ (construction), __str__ (string representation for print), __repr__ (detailed representation), __len__ (len()), __getitem__ (indexing []), __iter__ (iteration), __eq__ (==), __lt__ (<), __add__ (+), __enter__/__exit__ (with statement), __call__ (callable objects). Implementing them makes your classes work naturally with Python built-ins.

Answer

Special methods like __init__, __str__, __repr__, __eq__, __add__.
Used for operator overloading and customizing built-in behavior.
Example: obj1 + obj2 calls obj1.__add__(obj2).
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice