Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are all python magic methods available to all objects

Tags:

python

Am I correct in assuming that an object in Python has a default implementation of all magic methods (the ones surrounded by the double underscore, such as __init__)?

like image 997
wobbily_col Avatar asked Feb 14 '26 10:02

wobbily_col


1 Answers

No.

>>> object.__add__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'object' has no attribute '__add__'

Some of them do have default implementations, like __init__, but most of them don't.

like image 178
user2357112 supports Monica Avatar answered Feb 16 '26 00:02

user2357112 supports Monica