Python==与is对比
Python==与is对比
上一篇文章:Python浅拷贝与深拷贝下一篇文章:Python元类本节内容很少,为啥要单拿一篇来讲呢,因为很容易理解误区。
is用来比较是否引用同一个对象
==表示两个对象是否相等
实例:
import copy a=[1,2,3] b=a c=copy.copy(a) print("a的id:",id(a)) print("b的id:",id(b)) print("c的id:",id(c)) print("a==b",a==b) print("a is b",a is b) print("a==c",a==c) print("a is c",a is c)
结果:
a的id: 4421593864 b的id: 4421593864 c的id: 4421592584 a==b True a is b True a==c True a is c False
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16