Python if not

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

空列表,空字典,空元组

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

0, 非0

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())
原文地址:https://www.cnblogs.com/agilestyle/p/12198115.html