Magic Method

Noun · Development

Definitions

  1. A specially named method in Python (surrounded by double underscores, like `__init__`, `__getattr__`, `__add__`) that the interpreter calls implicitly in response to operations such as object construction, attribute access, or operator use. Also called dunder methods.

    In plain English: Special methods in Python with funny names like __init__ that get called automatically when you do things like create an object or use the + operator.

    Example: "I defined `__repr__` so the debugger shows something useful instead of `<Foo object at 0x7f3a>`."

Related Terms