python 布尔值

下列对象的布尔值都是False:

NONE;

False(布尔类型)

所有的值为零的数

       0(整型)

       0.0(浮点型)

       0L(长整型)

       0.0+0.0j(复数)

""(空字符串)

[](空列表)

()(空元组)

{}(空字典)

字典也能用户布尔测试

dict_1 = {}
dict_2 = {'a':123}
 
if dict_1:
    print('dict_1 is not null')
else:
    print('dict_1 is null')
 
if dict_2:
    print('dict_2 is not null')
else:
    print('dict_2 is null')

输出:

dict_1 is null
dict_2 is not null

可见,字典类型也能用于布尔测试。

原文地址:https://www.cnblogs.com/nyist-xsk/p/9336629.html