python 'is not' operator

后端 未结 4 2007
眼角桃花
眼角桃花 2020-12-13 23:47

I notice there is a comparison operator is not. Should I literally translate it into

!= 

instead of

== not
<         


        
4条回答
  •  轮回少年
    2020-12-14 00:22

    To expand on what Ignacio said:

    a == b and a != b test whether two objects have the same value. You can override an object's __eq__ and __ne__ methods to determine what that means.

    a is b and a is not b test whether two objects are the same thing. It's like doing id(a) == id(b)

提交回复
热议问题