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, 空
相关文章
相关标签/搜索