(經過網絡學習,整理的文章,如有侵權,私聊删除)
互動式程式設計
不需要建立腳本檔案,通過python解釋器的互動模式來編寫代碼
mac上在iTerm中輸入python即可啟動互動式程式設計。
$ python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
x=int(input("please input your age"))
please input your age10
x
10
2.建立腳本檔案,通過腳本參數調用解釋器開始執行腳本,直到腳本順序執行完畢, 解釋器不再有效。
建立python檔案test.py 檔案内容:print 'hello python'
$ python test.py
3.直接運作python腳本。
建立python檔案test.py,檔案内容:
! /usr/bin/python #python安裝目錄 可以用which python檢視
print 'hello python'
$chmod +x test.py #給腳本檔案添加可執行權限
$./test.py