What are magic methods in Python?
Standardized way to add built-in behavior to user-defined classes
Also known as dunder methods.
Name a common use-case for magic methods related to string representation.
__str__ is for end-users, while __repr__ is for developers.
What magic method is used for object initialization?
__init__
This method is called when an instance of a class is created.
Which magic methods control attribute access?
These methods manage how attributes are accessed, assigned, and deleted.
What magic method makes an instance callable?
__call__
Allows an instance to be called like a function.
Which magic methods define comparison operators?
__eq__ defines equality (==), while __lt__ specifies less than (<).
What magic methods are used for iteration?
__iter__ returns an iterator, and __next__ retrieves the next item.
Which magic methods are involved in context management?
__enter__ sets up the context, and __exit__ cleans it up.
What magic methods handle numeric operations?
__add__ is for addition (+), and __sub__ is for subtraction (-).