程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2023-06(4)

Python—None

发布于2019-08-05 11:26     阅读(498)     评论(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黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

1 0
收藏该文
已收藏

评论内容:(最多支持255个字符)