Python 中判断值为空

判断变量
python语言与其他语言不同,没有 NULL 类型,空用 none 来表示,但同时需要注意,none 是有数据类型的,type为‘Nonetype’。

  • 使用if x is not Noneif not (x is None)不直观,而if not x不适用于False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()等情况
  • is 判断是对象相同 , “==” 判断的是相等。
posted @ 2022-05-05 16:07  Oddpage  阅读(3152)  评论(0)    收藏  举报