Recommended way to implement __eq__ and __hash__

后端 未结 2 549
灰色年华
灰色年华 2021-02-13 11:30

The python documentation mentions that if you override __eq__ and the object is immutable, you should also override __hash__ in order for the class to

2条回答
  •  遥遥无期
    2021-02-13 11:58

    Is that the equivalent of this one-liner eq?

       def __eq__(self, other):
           return type(other) is type(self) and (self.a == other.a) and (self.b == other.b)
    

提交回复
热议问题