Understanding Python's “is” operator

前端 未结 11 2279
别那么骄傲
别那么骄傲 2020-11-21 22:42

The is operator does not match the values of the variables, but the instances themselves.

What does it really mean?

11条回答
  •  梦如初夏
    2020-11-21 23:15

    The is operator is nothing but an English version of ==. Because the IDs of the two lists are different so the answer is false. You can try:

    a=[1,2,3]
    b=a
    print(b is a )#True
    

    *Because the IDs of both the list would be same

提交回复
热议问题