is 和 == 的区别

2020-05-29  本文已影响0人  你的学生_张老师

== 是比较两个变量的,如果相同,就会返回True,否则返回False

is 是比较两个变量的内存地址,如果内存地址相同,返回True,否则返回False

>>> a = [1, 2, 3]
>>> b = [1, 2, 3]
>>> a == b
True
>>> a is b
False
>>> id(a)
4505566728
>>> id(b)
4504821192
>>> x = [2, 3, 4]
>>> y = x
>>> x == y
True
>>> x is y
True
>>> id(x)
4505231880
>>> id(y)
4505231880
上一篇下一篇

猜你喜欢

热点阅读