Why does “[] is [ ]” evaluate to False in python

前端 未结 4 833
無奈伤痛
無奈伤痛 2020-12-20 18:46

Try this in an interactive python shell.

[] is [ ]

The above returns False, why?

4条回答
  •  旧时难觅i
    2020-12-20 19:39

    [] is like list(), if you do this:

    a = list()
    b = list()
    

    clearly a and b are two completly different objects, hence:

    a is b # False
    

    like

    list() is list() # False
    

    like

    [] is [] # False
    

提交回复
热议问题