Understanding Python's “is” operator

前端 未结 11 2304
别那么骄傲
别那么骄傲 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条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 23:22

    As you can check here to a small integers. Numbers above 257 are not an small ints, so it is calculated as a different object.

    It is better to use == instead in this case.

    Further information is here: http://docs.python.org/2/c-api/int.html

提交回复
热议问题