在Python中,None、空列表[]、空字典{}、空元组()、0等一系列代表空和无的对象会被转换成False。除此之外的其它对象都会被转化成True。python变量初始化为空值分别是: 数值 digital_value = 0 字符串 str_value = "" 列表 list_value = [] 字典 ditc_value = {} 元组 tuple_value = () Python中关于空类型的判断使用的内建函数any(), any(iterable) Return True if any element of the iterable is true. If the iterable is empty, return False. Equivalent to:
def any(iterable): for element in iterable: if element: return True return False