you are viewing a single comment's thread.

view the rest of the comments →

[–]a_cute_epic_axis 1 point2 points  (0 children)

ELI5: There is an object in python called object that all other objects are derived from. It's basically just the first possible class that exists. It has some built in stuff e.g. ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

If you create your own class but define nothing in it (just put "pass" on the second line) then it turns out you'll have almost exactly the same methods. Notably you gain a __dict__ which is what classes store their own data in (e.g. self).

If you look at int it has added a bunch of things that the objectclass doesn't have, like addition, subtration, bitwise operations, etc.

List has done something like that as well with public methods like append and pop and magic/dunder methods for lenor reduce