Contenu connexe Similaire à 2010 08-19-30 minutes of python Similaire à 2010 08-19-30 minutes of python (11) 2010 08-19-30 minutes of python1. 30 minute of Python
Name : Kang-min Wang ( Aminzai )
Date : 2010/08/19
Email : aminzai –at-- aminzai.net
2. Outline
● 迷漾的 Outline....
2
2010/08/09 30 minutes Python
5. History
● Python 的創始人為吉多 · 范羅蘇姆。在 1989 年
聖誕節期間的阿姆斯特丹,吉多為了打發聖誕節
的無趣,決心開發一個新的指令碼解釋程式
● 我們究竟在幹嘛阿 ...
5
2010/08/09 30 minutes Python
6. Who use it?
● Google
● Youtube
● BitTorrent
● NASA
● OLPC
● Plurk
● Me 0.0-/
6
2010/08/09 30 minutes Python
8. Why Google use it?
● 由於 Python 對於 C 和其他語言的良好支援,很
多人還把 Python 作為一種「膠水語言」( glue
language )使用。使用 Python 將其他語言編寫
的程式進行整合和封裝。
8
2010/08/09 30 minutes Python
9. Python's Core ideology
● There is only one way to do it.
要做好一件事,一種方法就夠了。
● Everything is object.
萬物皆物件
● Readability counts.
可讀性優先
● Explicit is better than implicit.
明顯比隱晦好
● Simple is better than complex.
簡單比複雜好
9
2010/08/09 30 minutes Python
10. Advantage
● 簡單易讀
● 開發快速
● 易於協同開發
● 很快就可以上手
● 記憶體回收機制
● 養成良好習慣
10
2010/08/09 30 minutes Python
11. Shortcoming
● 速度仍然比 C 慢
● 有些超級老的 cpu 不能跑
● 有些模組比較肥 (xml 相關 )
11
2010/08/09 30 minutes Python
12. Develop Enviorment
● Eclipse + pyDev
● Python IDLE
● Vim <== 我在用的 XD
12
2010/08/09 30 minutes Python
13. st
1 example
Hello, World!
13
2010/08/09 30 minutes Python
14. Numbers
● 整數 (int)
● 浮點 (float)
● 長整數 (long)
● 八進位與十六進位
● 複數 (complex)
● 布林值 (bool)
14
2010/08/09 30 minutes Python
15. Operation
● + - * / ** //...
● 遵守四則運算規則
● 數學函式: pow abs...
● Modules : random math...
● 轉換進制: oct() hex()....
from decimal import Decimal
Decimal()
● 集合 set()
15
2010/08/09 30 minutes Python
16. String
● 字串 (str)
● Raw
● Unicode
● byte(in Python 3.0)
● + *...
● len()
● slice notation
● Replace ,Upper....
16
2010/08/09 30 minutes Python
17. Slice(array)
0 1 2 3 4 5
S L I C E
[: :]
[ 起使:終止:步進 ]
17
2010/08/09 30 minutes Python
18. List
● [ 'abc', 123 , [ 'a' , 'b' ] ]
● 可任意巢狀化,不限定型態
18
2010/08/09 30 minutes Python
19. Tuple
● ( 'abc', 123 , [ 'a' , 'b' ] )
● 內含物不可變更的 list
19
2010/08/09 30 minutes Python
20. Dict (Dictory)
● { 'name' : 'billy3321' ,'jobs' : ['student',
'maintainer'], 'develop' : {'name' : 'lazybuntu',
'OS' : 'Ubuntu' } }
● Key : Value
● 無序集合體,以 key 存取
● 以 hash table 實作
20
2010/08/09 30 minutes Python
21. File I/O
● myfile = open('myfile', 'w')
myfile.write('Hello, World!')
myfile.close()
● myfile = open('myfile', 'r')
myfile.readline()
myfile.readline()
myfile.readline()
myfile.readlines()
myfile.close
21
2010/08/09 30 minutes Python
22. Dynamic type?
● 整數,字串是不能改的?我明明就可以改他啊!
● A=3
B=A
print A , B
A = 'hello'
print A , B
● Refrence( 參照值 ) → object( 物件 )
● 屬性是屬於物件的,而變數就是參照值
● [ 'abc' , [(1, 2), ([3],4)],'def']
22
2010/08/09 30 minutes Python
23. [ 'abc' , [(1, 2), ([3],4)],'def']
'abc' (1, 2) ([3],4) 'def'
1 2 [3] 4
3
2010/08/09 23
26. 給你三秒鐘 !!
if (x)
if (y)
statement1;
else
statement;
else
statement2;
26
2010/08/09 30 minutes Python
29. 縮排
● 可讀性優先 ; readability counts
● 把習慣養好
● 方便大家協同作業,大家的程式碼一目瞭然。
29
2010/08/09 30 minutes Python
30. ●
While loop
● while true:
print "Spam"
else
print "Aminzai"
● while i < 5:
i=i+1
print i
● countinue break pass else
31. ●
For loop
● for i in lists:
print i
● for line in open('file'):
● 如果要反覆特定次數:搭配 range()
for i in range(5)
print "Spam"
32. Function
● def print_aminzai():
print "Aminzai"
print_aminzai()
● 利用 return 回傳值
● 注意:變數所存在之範圍
內建>廣域>函式>區域
33. Object
● class Person:
def __init__(self, name, job):
self.name = name
self.job = job
def info(self):
return (self.name, self.job)
aminzai = Person(‘Aminzai’, ‘student’)
aminzai.job
aminzai.info()
34. Object
● class man(Person):
self.sex = male
aminzai = man(‘aminzai’, ‘student’)
aminzai.sex
aminzai.info()
35. Document
● help()
● dir()
● Pydoc
● 說明文件和程式碼放在一起
35
2010/08/09 30 minutes Python
38. Fire Show!!
● Plurk BOT
● http://www.plurk.com/isu_ann
● Lazyscripts
● http://lazyscripts.org
● Google App Engines
● Geeklothes
– http://geeklothes-tw.appspot.com
● ECG Waveform
– http://isucsieeslabecg.appspot.com/SWF
● Conference Joke
38
2010/08/09
– http://confjoke.appspot.com/
30 minutes Python
39. Resource
● PyTUG:www.python.org.tw
● irc.://irc.freenode.net/#python.tw
● Ptt Python 討論版
● http://www.python.org/
39
2010/08/09 30 minutes Python
41. Next Topic
Hadoop
Or
My Develop Envirment
41
2010/08/09 30 minutes Python