Python 執行方式

在 Linux 執行 Python 的基本方式有 Python shell 或 Python script 這兩種,如果是使用 Raspberry Pi,而且是安裝 RASPBIAN DESKTOP 系統的話,那預設還有提供一套 IDLE 整合開發學習環境。
IDLE
如果使用 Raspberry Pi,而且是安裝 RASPBIAN DESKTOP 系統,可直接開啟 IDLE (整合開發學習環境):

Terminal
Python shell
在 Terminal (終端機) 輸入 python3 指令來訪問標準的內建 Python shell:
- 內建語法高亮。
- 支援自動完成功能。
- 可使用 Alt + p (上一個) / Alt + n (下一個) 查看歷史記錄。
可使用快速鍵 Ctrl + d、quit()
或 exit()
函數退出。
python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('Hello!')
Hello!
Python script
編寫一個簡單 Python script 的 hello.py 檔案 ,並執行它:
可以使用任何熟悉的編輯器撰寫,例如 Nano 或 Vim (可參考 vi、Vim 文字編輯器教學和常用按鍵與指令)
nano hello.py
print('Hello!')
python3 hello.py
Hello!
參考

本著作係採用創用 CC 姓名標示-相同方式分享 3.0 台灣 授權條款授權.