# class A: pass # a = A() # b = A() # print(a,b) # print(a==b) # eq 方法 # ==这个语法 是完全和__eq__相关的 class A: def __init__(self, name, age): self.name = name self.age = age def __eq__(self, other): if self.name == other.name and self.age == other.age: return True aa1 = A('Alex', 30) aa2 = A('Alex', 30) aa3 = A('Alex', 32) aa4 = A('Alex', 32) aa5 = A('Alex', 33) aa6 = A('Alex', 33) print(aa1==aa2)