== 是比较两个变量的值,如果值相同,就会返回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
网友评论