Python is 与 == 的区别

2018-11-08  本文已影响5人  一本大书
a = [1, 2, 3]
b = [1, 2, 3]

print("a = ", end='')
print(id(a))
print("b = ", end='')
print(id(b))

print("a is b   ", end='')
print(a is b)

print("a == b   ", end='')
print(a == b)

打印结果

a = 4332707720
b = 4332707784
a is b   False
a == b   True

is是用于判断 a b 是否指向同一个对象
==是用于判断 a b 的值是否相等

上一篇下一篇

猜你喜欢

热点阅读