Python == 和 is



  • a1 = [1,1,2]
    a2 = a1
    a1 == a2           
    # Out[21]: True
    a1 is a2
    # Out[22]: True
    
    a3 = a1.copy()
    a3 is a1 
    # Out[24]: False
    
    a3 == a1 
    # Out[25]: True
    

    ==

    ==在Python中是判断是否相等,比较两个对象中的值是否相等。==调用的对象__eq__()方法

    is

    is则是判断两个对象是否相同,是否是同一个对象。


 

Copyright © 2018 bbs.dian.org.cn All rights reserved.

Looks like your connection to Dian was lost, please wait while we try to reconnect.