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 ==?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章