我是靠谱客的博主 长情菠萝,这篇文章主要介绍python中的False的情况聚总,现在分享给大家,希望可以做个参考。

None是一个对象,其类型为None Type,其bool值为False;0是一个对象,其类型为int,其bool值为False

python中为False的对象有:

对于基本数据类型:

(1)bool type,False表示False,其他为True

(2)int and float type,0表示False,其他为True

(3)string type and  other string-like type including bytes和unicode:空字符表示False,其他为True

(4)序列类型(list,tuple,dict,set):空表示False,非空表示True

(5)None 永远表示 False

 

state = states.get('texas', None)
if not state:
....

等价于

if 'texas' not in states or states['texas'] is None or not states['texas']:
...

它有三种成立的情况:

  1. dict中不存在
  2. dict中存在,但值是None
  3. dict中存在而且也不是None,但是是一个等同于False的值,比如说空字符串或者空列表。

最后

以上就是长情菠萝最近收集整理的关于python中的False的情况聚总的全部内容,更多相关python中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(114)

评论列表共有 0 条评论

立即
投稿
返回
顶部