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

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

Try this in an interactive python shell.

[] is [ ]

The above returns False, why?

4条回答
  •  失恋的感觉
    2020-12-20 19:41

    The == operator compares the values of both the operands and checks for value equality. Whereas is operator checks whether both the operands refer to the same object or not.

    id('') : 139634828889200
    id('') : 139634828889200
    id('') : 139634828889200
    
    id([]) : 139634689473416
    id([]) : 139634689054536
    id([]) : 139634742570824
    

提交回复
热议问题