美文网首页
Python is 与 == 的区别

Python is 与 == 的区别

作者: 一本大书 | 来源:发表于2018-11-08 17:11 被阅读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 的值是否相等

    相关文章

      网友评论

          本文标题:Python is 与 == 的区别

          本文链接:https://www.haomeiwen.com/subject/opgwxqtx.html