问题:
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 ==?