python:bool函数返回假值的几种情况

返回假值,即False

1、空值Nnoe

2、所有数字0

  0

  0.0

  0+0j

3、空字符串、空列表、空字典、空集合、空元组、空字节串、空固定集合

In [136]: bool(None)
Out[136]: False

In [137]: bool(0)
Out[137]: False

In [138]: bool(0.0)
Out[138]: False

In [139]: bool(0+0j)
Out[139]: False

In [140]: bool(str())
Out[140]: False

In [141]: bool(list())
Out[141]: False

In [142]: bool(tuple())
Out[142]: False

In [143]: bool(set())
Out[143]: False

In [144]: bool(frozenset())
Out[144]: False

In [145]: bool(bytes())
Out[145]: False

In [146]: bool(dict())
Out[146]: False

 

posted @ 2020-12-08 18:13  昱成  阅读(663)  评论(0编辑  收藏  举报