class City():
def __init__(self,name):
self.name = name
def __eq__(self, city2):
return self.name.upper() == city2.name.upper()
one = City('HongKong')
two = City('hongkong')
three = City('myhome')
print(one == two)
print(one == three)
逻辑方法 | 说明 |
---|
__eq __(self,other) | self == other #等于 |
__ne __(self,other) | self != other #不等于 |
__lt __ self,other) | self < other #小于 |
__gt __(self,other ) | slef > other #大于 |
__le __(self, other) | self <= other #小于等于 |
__ge __(self, other) | self >= other #大于等于 |
数学方法 | 说明 |
---|
__add __(self, other) | self + other #加法 |
__sub __(self, other) | self - other #减法 |
__mul __(self, other) | self * other #乘法 |
__floordiv __(self, other ) | self //other #整数除法 |
__truediv __(self,other) | self / other #除法 |
__mod __(self,other) | self%other #余数 |
__pow __(self, other ) | self**other #次方 |