Senin, 18 Maret 2019

Python, should I implement __ne__() operator based on __eq__?

I have a class where I want to override the __eq__() operator. It seems to make sense that I should override the __ne__() operator as well, but does it make sense to implement __ne__ based on __eq__ as such?


class A:
def __eq__(self, other):
return self.value == other.value

def __ne__(self, other):
return not self.__eq__(other)

Or is there something that I'm missing with the way Python uses these operators that makes this not a good idea?



from Python, should I implement __ne__() operator based on __eq__?

Python, should I implement __ne__() operator based on __eq__? Rating: 4.5 Diposkan Oleh: Admin

0 komentar:

Posting Komentar

Popular Posts