-
Notifications
You must be signed in to change notification settings - Fork 0
[Python learning] Operator overload
Gukie edited this page Dec 20, 2017
·
2 revisions
Python可以复写 操作符 比如想要复写 +, 就在类中复写对应的 add 就可以了
Operator | Special Method | Description -- | -- |
-
| __add__(self, object) | Addition
-
| __sub__(self, object) | Subtraction
-
| __mul__(self, object) | Multiplication
** | pow(self, object) | Exponentiation / | truediv(self, object) | Division // | floordiv(self, object) | Integer Division % | mod(self, object) | Modulus == | eq(self, object) | Equal to != | ne(self, object) | Not equal to
| __gt__(self, object) | Greater than= | ge(self, object) | Greater than or equal to < | lt(self, object) | Less than <= | le(self, object) | Less than or equal to in | contains(self, value) | Membership operator [index] | getitem(self, index) | Item at index len() | len(self) | Calculate number of items str() | str(self) | Convert object to a string