Python Basic

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Python Basic - Presentation Transcript

        • Python- 快快樂樂寫程式
      酷學園教學團隊 雨蒼
    1. 個人背景
      • 雨蒼
      • 目前為 [email_address] 窗口
      • 完全沒摸過程式語言
      • 曾去巨 x 學過 C++ 但是跟他不熟
      • netman 老師教的 bash shell
      • 偷看過 python 教學影片
      • 加入 lazybuntu 邊寫邊學
    2. Python 的核心思維
      • There is only one way to do it. 要做好一件事,一種方法就夠了。
      • Everything is object. 萬物皆物件
      • Readability counts. 可讀性優先
      • Explicit is better than implicit. 明顯比隱晦好
      • Simple is better than complex. 簡單比複雜好
    3. Python 的 優點
      • 簡單易讀
      • 易於協同開發 ‏
      • 很快就可以上手
      • 記憶體回收機制
      • 養成良好習慣
    4. Python 的缺點
      • 速度仍然比 C 慢
      • 跨平台 - 使用 Python 模擬器 (PVM) ‏
      • 有些超級老的 cpu 不能跑
      • 有些模組比較肥 (xml 相關 ) ‏
    5. 誰在用 Python
      • Google
      • Youtube
      • BitTorrent
      • NASA
      • OLPC
      • Plurk
    6.  
    7. 執行第一個程式
      • 副檔名: py
      • 兩種作法:直譯器和執行 script
      • $ python 開啟互動介面
      • python *.py
      • #!/usr/bin/python #!/usr/bin/env python
      • chmod a+x *.py
      • ./*.py
      • 中文注意:固定檔案編碼為 UTF-8 # -*- coding: utf-8 -*-
    8. 如何寫出第一個程式
      • 打開 IDLE
      • Print "hello, world"
        • 思考:為什麼要加上雙引號?
    9. 為什麼要加上雙引號 (") ‏
      • $ python print6.py 6 6
      • 到底 6 要當成字看還是要當成數字?
      • 7 Traceback (most recent call last): File &quot;print6.py&quot;, line 4, in <module> print &quot;6&quot; + 1 TypeError: cannot concatenate 'str' and 'int' objects
        • 關於變數
    10. 數值 (numbers) ‏
      • 整數 (int) ‏
      • 浮點 (float) ‏
      • 長整數 (long) ‏
      • 八進位與十六進位
      • 複數 (complex) ‏
      • 布林值 (bool) ‏
    11. 數值運算與相關工具
      • + - * / ** //...
      • 遵守四則運算規則
      • 數學函式: pow abs...
      • Modules : random math...
      • 轉換進制: oct() hex().... from decimal import Decimal Decimal() ‏
      • 集合 set() ‏
    12. 字串 (string) ‏
      • 字串 (str) ‏
      • Raw
      • Unicode
      • byte(in Python 3.0) ‏
    13. 字串運算與相關工具
      • + *...
      • len()
      • slice notation
      • Replace ,Upper....
    14. Slice 0 1 2 3 4 5 [: :] [ 起使:終止:步進 ] E C I L S
    15. List
      • [ 'abc', 123 , [ 'a' , 'b' ] ]
      • 可任意巢狀化,不限定型態
    16. List 運算與相關工具
      • + *
      • len()
      • subscript and slice notation
      • extend , del , pop , sort
      • range() ‏
    17. Tuple
      • ( 'abc', 123 , [ 'a' , 'b' ] ) ‏
      • 內含物不可變更之 list
    18. 辭典 (Dictionary) ‏
      • { 'name' : 'billy3321' ,'jobs' : ['student', 'maintainer'], 'develop' : {'name' : 'lazybuntu', 'OS' : 'Ubuntu' } }
      • Key : Value
      • 無序集合體,以 key 存取
      • 以 hash table 實作
    19. 辭典運算與相關工具
      • keys values items
      • update() pop() del.....
    20. 檔案存取
      • myfile = open('myfile', 'w') myfile.write('hello study area hello sa taipei') myfile.close() ‏
      • myfile = open('myfile', 'r') myfile.readline() myfile.readline() myfile.readline() myfile.readlines() myfile.close
        • 思考:如何儲存變數?
    21. 使用 pickle 直接儲存物件
      • D={'a':1 , 'b':2 , 'c':3} import pickle file = open('datafile.txt', 'w') pickle.dump(D, file) file.close() F = open('datafile.txt', 'r') F.readlines() E = pickle.load(F) print E
        • 思考:為什麼整數,數字不能改?我明明就可以改!
        • 為什麼 List 自己會改變?
    22. 為什麼 Python 支援動態定型?
      • 整數,字串是不能改的?我明明就可以改他啊!
      • A = 3 B = A print A , B A = 'hello' print A , B
      • Refrence( 參照值 ) -> object( 物件 ) ‏
      • 屬性是屬於物件的,而變數就是參照值
      • [ 'abc' , [(1, 2), ([3],4)],'def']
    23. [ 'abc' , [(1, 2), ([3],4)],'def'] ' abc ' (1, 2) ([3],4) 'd ef ' 1 2 [3] 4 3
    24. 共用參照值與複製
      • L1 = [ 2 , 3 , 4 ] L2 = L1 L1[0] = 24
      • L1 = [ 2 , 3 , 4 ] L2 = L1[:] L1[0] = 24
    25. 小型整數或字串會重複使用
      • X = 32 Y = 32 X == Y X is Y
      • import sys sys.getrefcount(1) ‏
        • 關於語法
        • 思考:為什麼要縮排?
    26. 案例:兩個 if 的故事
      • if ( x ) if ( y ) statement1; else statement2;
      { { { } } } }
    27. Python 語法
      • 多了: 縮排
      • 少了 ( ) { } ;
      • 對你的鍵盤好一點
      • Readability counts.
    28. if
      • if a > b: print a, &quot;>&quot;, b elif a < b: print a, &quot;<&quot;, b else : print a, &quot;=&quot;, b
      • if not a:
      • 縮排建議固定使用空白
    29. 兩個 if 的故事 -Python 篇
      • if x : if y : statement1
      else: statement2 else: statement2
        • 思考:為什麼要這樣寫程式?
    30. 為什麼我一定要這樣寫程式?
      • 可讀性優先 ; readability counts
      • 把習慣養好
      • 方便大家協同作業,大家的程式碼一目瞭然。
    31. While
      • while true: print &quot;Spam&quot; else print &quot;sa tainan&quot;
      • while i < 5: i = i + 1 print i
      • countinue break pass else
    32. For
      • for i in lists: print i
      • for line in open('file'):
      • 如果要反覆特定次數:搭配 range() for i in range(5) print &quot;Spam&quot;
    33. 函式
      • def print_sa(): print &quot;Study Area&quot; print_sa() ‏
      • 利用 return 回傳值
      • 注意:變數所存在之範圍 內建>廣域>函式>區域
    34. 函式 引數 廣域變數 檔案 / 串流 區域變數 Return 可變更引數 廣域變數 檔案 / 串流 輸入 輸出
    35.  
    36. 模組
      • 找到檔案>編譯為 pyc >執行程式碼建立物件
      • 為了增加速度,模組匯入時會進行編譯。編譯為 pyc
      • 搜尋路徑: sys.path
    37.  
        • 關於說明文件
      • help()
      • dir()
      • Pydoc
      • 說明文件和程式碼放在一起
    38. 網路資源
      • PyTUG www. python.org.tw
      • irc.://irc.freenode.net/#python.tw
      • Ptt Python 討論版
    39. Python 的核心思維
      • There is only one way to do it. 要做好一件事,只有一種方法。
      • Everything is object. 萬物皆物件
      • Readability counts. 可讀性優先
      • Explicit is better than implicit. 明顯比隱晦好
      • Simple is better than complex. 簡單比複雜好
      • Import this – The Zen of Python
    40.  
    41.  
    SlideShare Zeitgeist 2009

    + billy3321billy3321 Nominate

    custom

    839 views, 1 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 839
      • 839 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 13
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories