Here has suppressed the basics (probably w), so I would like to work on the class as the next step.
--The declaration is "class Hoge:" --Inheritance is "class Hoge (Base1, Base2):" --The method is the same as the function "def func (self, ...):" --Anyway, the first argument of the method is "self" --The constructor is "def \ _ \ _ init \ _ \ _ (self, ...):" --Class variables can also be defined (in Java style) --Other than that, if you set it in "\ _ \ _ init \ _ \ _ ()", it will be the expected operation. --You can add more and more variables to the object (it feels strange to not declare it) --If you don't set a value for a variable, it's the same as if the variable doesn't exist
Tips
--Private functions (variables) are "\ _func ()", with an underscore in front and no underscore in the back.
--Static method is defined by " @ static method "
--You don't need "self" in the first argument
It seems that there are more functions, but even if you don't remember it for the time being, it seems quite so. I will see it when I need it.
| Method name | meaning |
|---|---|
| __init__ | constructor |
| __del__ | Destructor |
| __new__ | Instance allocator |
| __repr__ | Returns a string that represents the information of the object |
| __str__ | Converts an object to a string and returns it |
| __bytes__ | Convert object to bytes type and return |
| __format__ | Returns the object as a formatted string |
| __hash__ | Returns the hash value of the object |
| __bool__ | Called during Boolean operation |
| __lt__ | 「<Supports calculation |
| __le__ | 「<=Supports calculation |
| __eq__ | 「==Supports calculation |
| __ne__ | 「!=Supports calculation |
| __gt__ | 「>Supports calculation |
| __ge__ | 「>=Supports calculation |
| __getattr__ | Called when reading an attribute value that is not set in the object (except when it is registered) |
| __getattribute__ | Called (always) when reading an attribute value that is not set on an object |
| __setattr__ | Called when setting the attribute value of an object |
| __delattr__ | Called when deleting an object's attribute value |
| __dir__ | Returns a sequence of a list of members |
| __index__ | Returns an integer value |
| __add__ | 「+Corresponds to the operator (left term) |
| __sub__ | 「-Corresponds to the operator (left term) |
| __mul__ | 「*Corresponds to the operator (left term) |
| __truediv__ | 「/Corresponds to the operator (left term) |
| __floordiv__ | 「//Corresponds to the operator (left term) |
| __mod__ | 「%Corresponds to the operator (left term) |
| __divmod__ | 「divmod()Corresponds to the operator (left term) |
| __pow__ | 「**Corresponds to the operator (left term) |
| __lshift__ | 「<<Corresponds to the operator (left term) |
| __rshift__ | 「>>Corresponds to the operator (left term) |
| __and__ | 「&Corresponds to the operator (left term) |
| __xor__ | 「^Corresponds to the operator (left term) |
| __or__ | Corresponds to the " |
| __radd__ | 「+Corresponds to the operator (right term) |
| __rsub__ | 「-Corresponds to the operator (right term) |
| __rmul__ | 「*Corresponds to the operator (right term) |
| __rtruediv__ | 「/Corresponds to the operator (right term) |
| __rfloordiv__ | 「//Corresponds to the operator (right term) |
| __rmod__ | 「%Corresponds to the operator (right term) |
| __rdivmod__ | 「divmod()Corresponds to the operator (right term) |
| __rpow__ | 「**Corresponds to the operator (right term) |
| __rlshift__ | 「<<Corresponds to the operator (right term) |
| __rrshift__ | 「>>Corresponds to the operator (right term) |
| __rand__ | 「&Corresponds to the operator (right term) |
| __rxor__ | 「^Corresponds to the operator (right term) |
| __ror__ | Corresponds to the " |
| __iadd__ | 「+=Supports cumulative assignment statements |
| __isub__ | 「-=Supports cumulative assignment statements |
| __imul__ | 「*=Supports cumulative assignment statements |
| __itruediv__ | 「/=Supports cumulative assignment statements |
| __ifloordiv__ | 「//=Supports cumulative assignment statements |
| __imod__ | 「%=Supports cumulative assignment statements |
| __ipow__ | 「**=Supports cumulative assignment statements |
| __ilshift__ | 「<<=Supports cumulative assignment statements |
| __irshift__ | 「>>=Supports cumulative assignment statements |
| __iand__ | 「&=Supports cumulative assignment statements |
| __ixor__ | 「^=Supports cumulative assignment statements |
| __ior__ | 「|=Supports cumulative assignment statements |
| __neg__ | 「-Supports unary operators |
| __pos__ | 「+Supports unary operators |
| __abs__ | 「abs()Supports unary operators |
| __invert__ | 「^Supports unary operators |
| __complex__ | complex()Corresponds to |
| __int__ | int()Corresponds to |
| __float__ | float()Corresponds to |
| __round__ | round()Corresponds to |
| __instancecheck__ | Whether the class is a subclass, an instance of a subclass, or an instance of a virtual subclass |
| __subclasscheck__ | Whether the class is a subclass or a virtual subclass |
| __call__ | 「()Corresponds to the function call operator |
| __len__ | len()Corresponds to |
| __getitem__ | object[key]Corresponding to acquisition in |
| __setitem__ | object[key]Corresponds to the setting of |
| __delitem__ | del object[key]Corresponds to |
| __iter__ | Get an iterator |
| __reversed__ | reversed()Corresponds to |
| __contains__ | Supports acquisition by "item in object" |
| __get__ | Get attribute value with descriptor |
| __set__ | Set attribute value in descriptor |
| __delete__ | Delete attribute value in descriptor |
| __enter__ | Called with with statement in context manager |
| __exit__ | Called at the end of the execution context in the context manager |
Recommended Posts