我有一个Point
具有x
和y
属性的类。我想False
将一个Point
对象与任何其他类型的对象进行比较。例如,Point(0, 1) == None
失败:
AttributeError: 'NoneType' object has no attribute 'x'
班上:
class Point():
def __init__(self, x, y):
self.x = x
self.y = y
def __eq__(self, other):
return self.x == other.x and self.y == other.y
def __ne__(self, other):
return not self.__eq__(other)
如何配置__eq__
以False
与任何其他对象类型进行比较?