a = 3
b = 3
print(a == b)
print(a is b)
c = [1,2,3,4]
d = [1,2,3,4]
print(c == d)
print(c is d)
結果:
True
True
True
False
由於Python的內存管理機制比較複雜,而is比較的恰恰是內存id,因此一般儘量避免使用,如果需要比較兩個變量的值,儘可能使用 ==。
a = 3
b = 3
print(a == b)
print(a is b)
c = [1,2,3,4]
d = [1,2,3,4]
print(c == d)
print(c is d)
結果:
True
True
True
False
由於Python的內存管理機制比較複雜,而is比較的恰恰是內存id,因此一般儘量避免使用,如果需要比較兩個變量的值,儘可能使用 ==。
繼續運行 ?* 回憶上次內容 上次使用shell環境中的命令 命令 作用 c