原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/12198115.html

 

空列表,空字典,空元组

Python if not

 

空字符创,空白字符串,False,True,None

Python if not

0, 非0

Python if not

 

Summary

None,False,0,空列表[],空字典{},空元祖(),空字符串(不是空白字符串)都相当于false

所以Python中判定字符串是否为空的方法示例如下

def is_blank(input_str):
    return not (input_str and input_str.strip())


def is_not_blank(input_str):
    return bool(input_str and input_str.strip())

相关文章:

  • 2021-08-21
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2021-08-14
  • 2022-03-04
  • 2022-12-23
猜你喜欢
  • 2022-02-18
  • 2022-12-23
  • 2021-07-18
  • 2021-06-29
  • 2022-12-23
  • 2021-07-28
相关资源
相似解决方案