class Goods: def __init__(self,name): self.name = name def __eq__(self,other): #self = apple1, other = apple2 if self.name == other.name: return True else: return False apple1 = Goods('apple') apple2 = Goods('apple') print(apple1 == apple2) #True, 双等号==触发双下__eq__方法