Python None 比较:我应该使用“is”还是 ==? - Python None comparison: should I use “is” or ==?

问题:

My editor warns me when I compare my_var == None , but no warning when I use my_var is None .当我比较my_var == None ,我的编辑器会警告我,但当我使用my_var is None时没有警告。

I did a test in the Python shell and determined both are valid syntax, but my editor seems to be saying that my_var is None is preferred.我在 Python shell 中做了一个测试并确定两者都是有效的语法,但我的编辑器似乎在说my_var is None是首选。

Is this the case, and if so, why?是这样吗,如果是,为什么?


解决方案:

参考一: https://stackoom.com/question/xmOL
参考二: Python None comparison: should I use “is” or ==?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章