发布于2019-08-05 11:26 阅读(612) 评论(0) 点赞(1) 收藏(2)
None是一个特殊的常量。
None不是False。
None不是0。
None不是空字符串。
None有自己的数据类型NoneType
,并且是NoneType
中唯一的值。
None只是一个空值的对象,可以将None赋值给任何变量,但不能创建其他NoneType
对象。
Python中哪些形式的数据为空呢?
常量None
常量False
空列表
空元组
空集合
空字典
整数0
浮点数0.0
空字符串''
None一般用于函数中表示参数的缺省
def func(a, b=None):
if b is None:
print('b is None')
if a is not None:
print('a :', a)
a = None
print('a :', a)
print('a is not None :', a is not None)
print('not None :', not None)
return None
if not func(666):
print('not func(666) -> True')
输出结果:
b is None
a : 666
a : None
a is not None : False
not None : True
not func(666) -> True
最后来加深一下印象
bool(None) # False
not None is bool(not None) # True
# How to use ↓
object is None # None和任何其他数据类型对象比较永远返回False
object is not None
作者:大壮
链接:https://www.pythonheidong.com/blog/article/4322/2c9108f1453dc44bcc86/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!