Python中关于空类型的判断

 在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
New in version 2.5.
对于官方给出的解释可能会存在一些歧义,可以 参考实例教程自行理解

猜你喜欢

转载自blog.csdn.net/yongwan5637/article/details/80167297