Print and None 输出和无

Python,想vsstuido里就是集成

但是git里也可以写Py,

Git里写的Python叫做 Python interpreter Python解释器

下面是运行图

内容 详情
路径 MINGW64:/g/File/HPY/CS61A
用户及终端 15715@SGin MINGW64
Python版本 Python 3.9.11 (tags/v3.9.11:2de452f, Mar 16 2022, AMD64) on win32
提示信息 Type “help”, “copyright”, “creates” or “license”
命令及输出
>>> -2 -2
>>> print(-2) -2
>>> 'Day and Day' ‘Day and Day’
>>> print('Day and Day') Day and Day
>>> None
>>> print(None) None
界面设计
背景颜色 黑色
文字颜色 路径信息为白色,Python版本中括号和标签为彩色
命令行排版 左侧为输入命令(>>>开头),右侧对齐输出结果
分隔符 使用---分隔不同部分

PY里你输入什么,Py就会直接输出什么

但是None比较特殊,None本身就表示的是空类型,不代表任何的输出

Print则是完全的全部打印,这时,不把None所谓一个特殊的空类

还有一个好玩的点

输入的Python代码 >>> print(print(1), print(2)) (紫色字体,位于框内上方)
执行输出 1
2
None None
背景与边框 白色背景,长方形边框

这个就是好玩的点

这个可以画一个表达树,先调用pinrt(1),然后输出1

然后调用print(2),然后输出2,然后在调用pirnt(None,None)

因为Print的返回值是None,所以答案是最后的这样

None注意的三点

None Indicates that Nothing is Returned

None 表示没有返回任何内容

The special value None represents nothing in python

在Python中,特殊值 None 代表”无”

A function that does not explicitly return a value will return None

如果一个函数没有显式地返回值,它将返回 None

Careful: None is not displayed by the interpreter as the value of an expression

注意:解释器不会将 None 显示为表达式的值

Python你只要不给函数返回值,这个函数就是返回None

而且可以给None起一个别名

类似

six=None,是合法的

six后面就可以起到None的作用

Pure Funcions 纯函数,没有副作用,只是返回一个具体的值或表达式的函数

Non-pure Functions 有副作用的函数

比如

就是你没有返回值,但是这个函数里面有输出,这样,只要你调用这个函数,就会产生输出