Python基礎 第乙個Python程式(2)

2022-07-04 09:09:06 字數 1651 閱讀 4324

(1)【開始】|【執行】,輸入cmd回車,進入windows命令介面。

(2)輸入python,回車,進入python shell。

python開始選單中點選idle,啟動python shell。

')其中,**行

line 1:linux**移植

line 2:檔案編碼,可避免出現中文亂碼情況

將原始碼py檔案編譯成位元組碼pyc檔案:

(1)單個生成pyc檔案

命令方式:

python -m py_compile hello_world.py

指令碼方式:

啟動python idle

(2)批量生成pyc檔案

指令碼方式:

>>> import

compileall

>>> if

__name__=='

__main__':

compileall.compile_dir(r

'f:\projects

')

python -o -m py_compile hello_world.py

python -o -m compileall hello_world.py
優化編譯後生成的檔案:__pycache__/hello_world.cpython-37.opt-1.pyc

python -oo -m py_compile hello_world.py

python -oo -m compileall hello_world.py
優化編譯後生成的檔案:__pycache__/hello_world.cpython-37.opt-2.pyc

-o引數:生成更加緊湊的優化後的位元組碼

-oo引數:進一步移除-o選項生成的優化後的位元組碼檔案中的文件字串

python第乙個程式設計 第乙個 Python 程式

簡述 安裝完 python 後,windows 中 開始選單或安裝目錄下就會有 idle 開發 python 程式的基本 ide 整合開發環境 幫助手冊 模組文件等。linux 中 只需要在命令列中輸入 python 命令即可啟動互動式程式設計。互動式程式設計 互動式程式設計不需要建立指令碼檔案,是...

Python基礎 第乙個 Python 程式

python 程式的 副檔名 通常都是 py 在終端中輸入以下命令執行 01 hellopython.py python 01 hellopython.pyprint 是 python 中我們學習的第乙個 函式 print 函式的作用,可以把 內部的內容,輸出到螢幕上 關於錯誤 每乙個程式設計師都是...

python基礎 第乙個 Python 程式

02.python 2.x 與 3 x 版本簡介 03.執行 python 程式的三種方式 3.2.互動式執行 python 程式 2 退出 官方的直譯器 3 ipython ipython 的安裝 3.3.python 的 ide pycharm python 源程式就是乙個特殊格式的文字檔案,可...