python代碼`if not x:` 和`if x is not None:`和`if not x is None:`使用

代碼中常常會有變量是否爲None的判斷,有三種主要的寫法:html  第一種是`if x is None`;python 第二種是 `if not x:`;git 第三種是`if not x is None`(這句這樣理解更清晰`if not (x is None)`) 。github 若是你以爲這樣寫沒啥區別,那麼你可就要當心了,這裏面有一個坑。先來看一下代碼:函數 >>> x = 1 >>>
相關文章
相關標籤/搜索