python命令行模式的用法及流程
1、使用cmd打開命令行窗口。
2、在輸入python時(shí),進(jìn)入python交互模式。
3、輸入exit(),退出交互模式,在命令行模式下運(yùn)行.py程序。
實(shí)例
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
文件名、目錄名或卷標(biāo)語法不正確。
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
>>>
知識(shí)點(diǎn)擴(kuò)充:
命令行模式與python交互模式
1.在命令行模式下,可以執(zhí)行 python 進(jìn)入 Python 交互式環(huán)境,也可以執(zhí)
行 python hello.py 運(yùn)行一個(gè).py 文件。
2.在 Python 交互式環(huán)境下,只能輸入 Python 代碼并立刻執(zhí)行。
3.Python 交互式環(huán)境會(huì)把每一行 Python 代碼的結(jié)果自動(dòng)打印出來,但是,直接運(yùn)行 Python 代碼卻不會(huì)。
到此這篇關(guān)于python命令行模式的用法及流程的文章就介紹到這了,更多相關(guān)python命令行模式的使用流程內(nèi)容請(qǐng)搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。