import copy
a = 12
# b = a
b = 12
print(a is b)
c = copy.deepcopy(a)
print(a is c)
class Person(object):
def __init__(self, name):
self.name = name
p1 = Person('ff')
p2 = Person('ff')
print(p1==p2)
print(p1 is p2)
print(Person.__eq__)
class Person(object):
def __init__(self, name):
self.name = name
def __eq__(self, object_per): # 重定义类的__eq__方法,可自定义类的比较
return self.name == object_per.name
p1 = Person('ff')
p2 = Person('ff')
print(p1 == p2)
print(p1 is p2)
运行结果:
True
True
False
False
<slot wrapper '__eq__' of 'object' objects>
True
False