python中if not x: 和 if x is not None: 和 if not x is None的使用和區別(這裏面有一個坑)

前言:代碼中常常會有變量是否爲None的判斷,有三種主要的寫法: 第一種是if x is None 第二種是 if not x: 第三種是if not x is None(這句這樣理解更清晰if not (x is None)) 若是你以爲這樣寫沒啥區別,那麼你可就要當心了,這裏面有一個坑。python 開始以前你必需要有一個這樣的認識,清楚x等於None, False, 空字符串"", 0, 空
相關文章
相關標籤/搜索