__new__(cls, *args, **kwargs)
Called to create a new instance of a class \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
__init__(self, *args, **kwargs)
Called after instance is created by __new__
_________________________________
__del__(self)
Called when an instance is about to be destroyed
_________________________________
__repr__(self)
The “official” string representation of an object
_________________________________
__str__(self)
The “informal” string representation of an object
_________________________________
__bytes__(self)
Called by bytes() to compute a byte-string representation of an object, returning a bytes object
__format__(self, format_spec)
The “formatted” string representation of an object
_________________________________
The so-called “rich comparison” methods
\_\_lt\_\_(self, other) \_\_le\_\_(self, other) \_\_eq\_\_(self, other) \_\_ne\_\_(self, other) \_\_gt\_\_(self, other) \_\_ge\_\_(self, other) \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
__hash__(self)
Called by built-in hash() and for operations on members of hashed collections like set, frozen set, and dict
_________________________________
def \_\_hash\_\_(self):
return hash((self.name, self.nick, self.color))__bool__(self)
Called to implement truth value testing
_________________________________
__getattr__(self, name)
Called when default attribute access fails with an AttributeError (when __getattribute__ or __get__ raises the exception)
_________________________________
__getattribute__(self, name)
Called unconditionally to implement attribute accesses for instances of the class \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
__setattr__(self, name, value)
Called when an attribute assignment is attempted
_________________________________
__delattr__(self, name)
Called when attribute deletion is attempted
_________________________________
__dir__(self)
Called when dir() is called on the object, returning a sequence
_________________________________
dir([object]):
Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.
If the object has a method named __dir__(), this method will be called and must return the list of attributes. This allows objects that implement a custom __getattr__() or __getattribute__() function to customize the way dir() reports their attributes.
__get__(self, instance, owner=None)
Descriptor - only applies when an instance of the descriptor class (where this method is defined) is used as an attribute in the owner class (appears in the class dictionary for the class or its parents)
Called to get the attribute of the owner class (or an instance of the owner class)
__set__(self, instance, value)
Descriptor - only applies when an instance of the descriptor class (where this method is defined) is used as an attribute in the owner class (appears in the class dictionary for the class or its parents)
Called to set the attribute on an instance of the owner class to a new value
__delete__(self, instance)
Descriptor - only applies when an instance of the descriptor class (where this method is defined) is used as an attribute in the owner class (appears in the class dictionary for the class or its parents)
Called to delete the attribute on an instance of the owner class
__set_name__(self, owner, name)
Descriptor - only applies when an instance of the descriptor class (where this method is defined) is used as an attribute in the owner class (appears in the class dictionary for the class or its parents)
Called at the time the owning class is created, assigning the attribute name to the descriptor \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
__slots__
Not a method, a class variable that allows us to explicitly declare data members (like properties) and deny the creation of \_\_dict\_\_ (space saved can be significant, as well as attribute lookup speed) and \_\_weakref\_\_ \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
class MyClass:
\_\_slots\_\_ = ['name', 'age']
def \_\_init\_\_(self, name, age):
self.name = name
self. age = age__enter__(self)
Enter the runtime context related to this object
__exit__(self, exc_type, exc_value, traceback)
Exit the runtime context related to this object
_________________________________
__len__(self)
Called to implement len()
_________________________________
__getitem__(self, key)
Called to implement evaluation of self[key] (indexing)
_________________________________