Python—None
2019-08-01 21:19
1226 查看
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
相关文章推荐
- python None与Null
- Python3.6中bs4.BeautifuSoup对象的findall:NoneType object is not callable
- Python开发调用语音模块报错:TypeError:NoneTypetakesnoarguments
- python : 'NoneType' object has no attribute 'recv'
- python代码 if not x: 和 if x is not None: 和 if not x is None:使用介绍
- python输出结果后面带着一个“None”
- python none
- python3.x, cv2.imread()导入图片失败,none
- python里遇到字典里key值为None的情况,取不出来。
- python的reverse函数翻转结果为None
- ppython None Null区别
- python is not None
- python进阶:switch语句、推导式与None类型
- python中安装包出现Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))…………
- Python中的None与 NULL(即空字符)的区别
- Python 中的 None 与真假
- Python中TypeError: Unsupported data type: class NoneType和IndentationError: unexpected indent两个异常
- Python 内建函数 - open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None...)
- None, Python 的 Null 对象
- Python 内建函数 - property(fget=None, fset=None, fdel=None, doc=None)