python :算术运算符重载,关系运算符重载

ernestwang 823 0

算术运算符重载   # 当对象出现在 '+' 的左边时会自动触发 def __add__(self, other):   # 当对象出现在 '+' 的右边时会自动触发 def __radd__(self, other):   # '+='运算时会自动触发,若没有实现则会尝试__add__ def __iadd__(self, other): 关系运算符重载   # 大于:> def __gt__(self, other):   # 大于等于:>= def __ge__(self, other):   # 小于:< def __lt__(self, other): # 小于等于:<= def __le__(self, other): # 等于:== def __eq__(self, other): # 不等于:!=,当没写时会尝试__eq__ def __ne__(self, other):  

标签: 运算符重载 python

发布评论 0条评论)

还木有评论哦,快来抢沙发吧~

复制成功
微信号: irenyuwang
关注微信公众号,站长免费提供流量增长方案。
我知道了