魔法方法
class myclass:
def __eq__(self, other):
他重写了所有的==,操作.
而我想要的效果是,仅当与同类比较时候采用这个__eq__
请问如何优雅地实现
#目前的做法,但不优雅
def __eq__(self, other):
if type(other)==type(self):
return self.value==other.value
else:
super(SBTNode, self).__eq__(other)
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
不知道更简洁的