Python 中判断值为空
判断变量
python语言与其他语言不同,没有 NULL 类型,空用 none 来表示,但同时需要注意,none 是有数据类型的,type为‘Nonetype’。
- 使用
if x is not None,if not (x is None)不直观,而if not x不适用于False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()等情况 - is 判断是对象相同 , “==” 判断的是相等。
判断变量
python语言与其他语言不同,没有 NULL 类型,空用 none 来表示,但同时需要注意,none 是有数据类型的,type为‘Nonetype’。
if x is not None,if not (x is None)不直观,而if not x不适用于False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()等情况