Why does id({}) == id({}) and id([]) == id([]) in CPython?

后端 未结 3 2119
北荒
北荒 2020-11-22 06:03

Why does CPython (no clue about other Python implementations) have the following behavior?

tuple1 = ()
tuple2 = ()                                                    


        
3条回答
  •  情话喂你
    2020-11-22 06:28

    The == operator on lists and dicts do not compare the object IDs to see if they the same object - use obj1 is obj2 for that.

    Instead the == operator compares the members of the list of dict to see if they are the same.

提交回复
热议问题