下列对象的布尔值都是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

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

相关文章:

  • 2022-12-23
  • 2022-02-08
  • 2022-02-06
  • 2021-06-22
  • 1970-01-01
  • 2022-12-23
  • 2022-12-23
  • 2023-04-11
猜你喜欢
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-31
相关资源
相似解决方案