What is the difference between “ is None ” and “ ==None ”

后端 未结 5 902
无人共我
无人共我 2020-11-22 11:33

I recently came across this syntax, I am unaware of the difference.

I would appreciate it if someone could tell me the difference.

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 11:58

    The answer is explained here.

    To quote:

    A class is free to implement comparison any way it chooses, and it can choose to make comparison against None mean something (which actually makes sense; if someone told you to implement the None object from scratch, how else would you get it to compare True against itself?).

    Practically-speaking, there is not much difference since custom comparison operators are rare. But you should use is None as a general rule.

提交回复
热议问题