Python
20160827
大綱
- 學會 Python 執行方法
- 了解 變數種類
- 了解 控制流程
- 了解 讀黨,輸出檔案
學會 Python 執行方法
直接進入terminal
- 用spotlight 參考右側http://applefans.today/blog/1545841938
- 打terminal 就可以選到
- 切換路徑到桌面 先打 cd Desktop/
- 開啟新檔案 touch test.py
- 你應該會在桌面上看見 test.py 但用visual studio code 來看應該都是空值
兩種執行方法
使用script 在terminal 裡面打python [檔案.py] 按下enter
直接打入python 進入互動模式, 本圖追加 print "hello world"
參考文件
- Diango Girls' Turtorial
變數(自己看)
- 數字 a = 1
- 文字 b = 'abc'
- List c = [123,456,789]
- Dict d = {"a":123,"b":"aaaa","c":"asdfafaf"}
運算子(自己看)
- +
- -
- *
- /
- ==
- and
- or
- %
第一個重要函式
例如: 輸出 Hello world! aha
print "Hello world! %s"%("aha")
控制(自己看)
- if ... elif ... else
- while
- for ... in ...
讀檔案
with open('檔案路徑','r') as f:
records = f.readlines()
這樣就能把該檔案內容全部放入records之內
輸出到檔案
with open('檔案路徑','w+') as f:
f.write(文字)
這樣這個檔案就會放入文字內容
資料處理流程
- 拿到檔案
- 讀入檔案
- 處理資料
- 寫入檔案
- 交付檔案
額外工作
- 自動化以上流程
作業
請做出99乘法表