Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 默认情况下,_eq__()方法中包含哪些内容_Python_Python 3.x - Fatal编程技术网

Python 默认情况下,_eq__()方法中包含哪些内容

Python 默认情况下,_eq__()方法中包含哪些内容,python,python-3.x,Python,Python 3.x,我(从)读到: 默认情况下,用户定义的类具有\uuuuuuueq\uuuuuuuo()和\uuuuuuuuuuuuuuuuuuuuuu散列()方法;使用它们,所有对象比较不相等(除了它们自己)和x.\uuuu hash\uuuu()返回一个适当的值,使得x==y意味着x是y,而hash(x)==hash(y) 我想知道默认情况下\uuuu eq\uuu()方法的定义如下: def __eq__(self, other): return hash(self) == hash(other)

我(从)读到:

默认情况下,用户定义的类具有
\uuuuuuueq\uuuuuuuo()
\uuuuuuuuuuuuuuuuuuuuuu散列()
方法;使用它们,所有对象比较不相等(除了它们自己)和
x.\uuuu hash\uuuu()
返回一个适当的值,使得x==y意味着x是y,而hash(x)==hash(y)

我想知道默认情况下
\uuuu eq\uuu()
方法的定义如下:

def __eq__(self, other):
    return hash(self) == hash(other)
不,更像是:

def __eq__(self, other)
    return self is other

您不能使用
hash()
,因为不同的对象可能具有相同的哈希值。

您可以阅读以下参考:

在默认方法中,您只需尝试比较两个对象,而不覆盖eq,它将查看它们是否是相同的两个对象,更类似于以下内容:

def __eq__(self, other)
    return self is other
你可以参考


它解释了如何正确地将
\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。你将如何检查不易损坏的东西?:)