Python None 值
来源:互联网 发布:网络中猴子是什么意思 编辑:程序博客网 时间:2024/05/22 07:03
Python None 值
在 Python 中有一个值称为 None,它表示没有值。None 是 NoneType 数据类型的唯一值。就像布尔值 True 和 False 一样,None 必须大写首字母 N。
如果你希望变量中存储的东西不会与一个真正的值混淆,这个没有值的值就可能有用。有一个使用 None 的地方就是 print( )的返回值。print( )函数在屏幕上显示文本,但它不需要返回任何值,这和 len( ) 或 input( ) 不同。但既然所有函数调用都需要求值为一个返回值,那么 print( )就返回 None。要看到这个效果,请在交互式环境中输入以下代码。
Microsoft Windows [版本 6.1.7601]版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:\Users\foreverstrong>pythonPython 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> return_value = print("Hello World!")Hello World!>>> None == return_valueTrue>>> exit()C:\Users\foreverstrong>
在幕后,对于所有没有 return 语句的函数定义,Python 都会在末尾加上 return None。这类似于 while 或 for 循环隐式地以 continue 语句结尾。而且,如果使用不带值的 return 语句(也就是只有 return 关键字本身), 那么就返回 None。
References
[1] (美) Al Sweigart (斯维加特) 著;王海鹏 译. Python编程快速上手:让繁琐工作自动化[M]. 北京:人民邮电出版社, 2016. 1-391
阅读全文
0 0
- Python None 值
- None Python
- python 返回值(return)None
- 【Python】Python中的None
- Python中的None
- python is not None
- Python 中得None
- 关于python中的none
- python None与Null
- Python中的None
- python中的None
- python None与Null
- python None与Null
- python None与Null
- python过滤None
- Python中的None
- python None与Null
- python 中的None
- mvscp140.dll文件下载,解决找不到mvscp140.dll的问题
- 模拟加速的时钟
- Linux 上的基础网络设备详解
- 基础篇 3. 深入Servlet技术
- validate-binary-search-tree
- Python None 值
- 头条面试题
- Noip 2017 总结
- java接口1
- Driving E-ink display
- jquery 判断元素是否在数组内
- java接口2
- Oracle 11g R2安装手册(图文教程)For Windows -yellowcong
- 缓存数据预热详解