1、使用cmd打开命令行窗口。

2、在输入python时,进入python交互模式。

3、输入exit(),退出交互模式,在命令行模式下运行.py程序。

实例

c:\users\86178>python
python 3.8.3 (default, jul 2 2020, 17:30:36) [msc v.1916 64 bit (amd64)] :: anaconda, inc. on win32
type “help”, “copyright”, “credits” or “license” for more information.
>>> edit
traceback (most recent call last):
file “<stdin>”, line 1, in <module>
nameerror: name ‘edit’ is not defined
>>> exit()

c:\users\86178>python
python 3.8.3 (default, jul 2 2020, 17:30:36) [msc v.1916 64 bit (amd64)] :: anaconda, inc. on win32
type “help”, “copyright”, “credits” or “license” for more information.
>>> hello.py
traceback (most recent call last):
file “<stdin>”, line 1, in <module>
nameerror: name ‘hello’ is not defined
>>> exit()

c:\users\86178>python hello.pu
python: can’t open file ‘hello.pu’: [errno 2] no such file or directory

c:\users\86178>python hello.py
python: can’t open file ‘hello.py’: [errno 2] no such file or directory

c:\users\86178>cd /d
文件名、目录名或卷标语法不正确。

c:\users\86178>cd /d d:

d:\>python hello.py
hello
d:\>python
python 3.8.3 (default, jul 2 2020, 17:30:36) [msc v.1916 64 bit (amd64)] :: anaconda, inc. on win32
type “help”, “copyright”, “credits” or “license” for more information.
>>> hello.py
traceback (most recent call last):
file “<stdin>”, line 1, in <module>
nameerror: name ‘hello’ is not defined
>>>

知识点扩充:

命令行模式与python交互模式

1.在命令行模式下,可以执行 python 进入 python 交互式环境,也可以执

行 python hello.py 运行一个.py 文件。

2.在 python 交互式环境下,只能输入 python 代码并立刻执行。

3.python 交互式环境会把每一行 python 代码的结果自动打印出来,但是,直接运行 python 代码却不会。

到此这篇关于python命令行模式的用法及流程的文章就介绍到这了,更多相关python命令行模式的使用流程内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!