为了账号安全,请及时绑定邮箱和手机立即绑定

__eq__如何在Python中以什么顺序处理?

__eq__如何在Python中以什么顺序处理?

一只甜甜圈 2019-10-19 14:39:47
由于Python不提供其比较运算符的左/右版本,因此它如何决定调用哪个函数?class A(object):    def __eq__(self, other):        print "A __eq__ called"        return self.value == otherclass B(object):    def __eq__(self, other):        print "B __eq__ called"        return self.value == other>>> a = A()>>> a.value = 3>>> b = B()>>> b.value = 4>>> a == b"A __eq__ called""B __eq__ called"False这似乎同时调用了两个__eq__函数。只是在寻找官方决策树。
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 866 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信