- == 用于判断值是否相同
- is 用于判断是否是同一对象、同一地址
>>> a = b = [1, 2, 3]
>>> c = [1, 2, 3]
'''值相同'''
>>> print(a == b)
True
>>> print(a == c)
True
'''同一对象,同一地址'''
>>> print(a is b)
True
'''非同一对象,不同对象,不同地址'''
>>> print(a is c)
False
>>> a = b = [1, 2, 3]
>>> c = [1, 2, 3]
'''值相同'''
>>> print(a == b)
True
>>> print(a == c)
True
'''同一对象,同一地址'''
>>> print(a is b)
True
'''非同一对象,不同对象,不同地址'''
>>> print(a is c)
False
本文标题:Python 中的 == 与 is
本文链接:https://www.haomeiwen.com/subject/rximoftx.html
网友评论