2010 08-19-30 minutes of python
TRANSCRIPT
30 minute of Python30 minute of Python
NameName :: Kang-min Wang ( Aminzai )Kang-min Wang ( Aminzai )DateDate :: 2010/08/192010/08/19EmailEmail :: aminzai –at-- aminzai.netaminzai –at-- aminzai.net
2010/08/09 30 minutes Python
2
OutlineOutline
● 迷漾的 Outline....
2010/08/09 30 minutes Python
3
What's Python?What's Python?
一條蟒蛇?
2010/08/09 30 minutes Python
4
What's Python?What's Python?
2010/08/09 30 minutes Python
5
HistoryHistory
● Python 的創始人為吉多 · 范羅蘇姆。在 1989 年聖誕節期間的阿姆斯特丹,吉多為了打發聖誕節的無趣,決心開發一個新的指令碼解釋程式● 我們究竟在幹嘛阿 ...
2010/08/09 30 minutes Python
6
Who use it?Who use it?
● Google● Youtube● BitTorrent● NASA● OLPC● Plurk● Me 0.0\-/
2010/08/09 30 minutes Python 7
2010/08/09 30 minutes Python
8
Why Google use it?Why Google use it?
● 由於 Python 對於 C 和其他語言的良好支援,很多人還把 Python 作為一種「膠水語言」( glue language )使用。使用 Python 將其他語言編寫的程式進行整合和封裝。
2010/08/09 30 minutes Python
9
Python's Core ideologyPython'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.簡單比複雜好
2010/08/09 30 minutes Python
10
AdvantageAdvantage
● 簡單易讀● 開發快速● 易於協同開發● 很快就可以上手● 記憶體回收機制● 養成良好習慣
2010/08/09 30 minutes Python
11
ShortcomingShortcoming
● 速度仍然比 C 慢● 有些超級老的 cpu 不能跑● 有些模組比較肥 (xml 相關 )
2010/08/09 30 minutes Python
12
Develop EnviormentDevelop Enviorment
● Eclipse + pyDev● Python IDLE● Vim <== 我在用的 XD
2010/08/09 30 minutes Python
13
11stst example example
Hello, World!
2010/08/09 30 minutes Python
14
NumbersNumbers
● 整數 (int)● 浮點 (float)● 長整數 (long)● 八進位與十六進位● 複數 (complex)● 布林值 (bool)
2010/08/09 30 minutes Python
15
OperationOperation
● + - * / ** //...● 遵守四則運算規則● 數學函式: pow abs...● Modules : random math...● 轉換進制: oct() hex()....
from decimal import DecimalDecimal()
● 集合 set()
2010/08/09 30 minutes Python
16
StringString
● 字串 (str)● Raw● Unicode● byte(in Python 3.0)● + *...● len() ● slice notation● Replace ,Upper....
2010/08/09 30 minutes Python
17
Slice(array)Slice(array)
S L I C E
0 1 2 3 4 5
[: :]
[ 起使:終止:步進 ]
2010/08/09 30 minutes Python
18
ListList
● [ 'abc', 123 , [ 'a' , 'b' ] ]● 可任意巢狀化,不限定型態
2010/08/09 30 minutes Python
19
TupleTuple
● ( 'abc', 123 , [ 'a' , 'b' ] )● 內含物不可變更的 list
2010/08/09 30 minutes Python
20
Dict (Dict (Dictory)Dictory)
● { 'name' : 'billy3321' ,'jobs' : ['student', 'maintainer'], 'develop' : {'name' : 'lazybuntu', 'OS' : 'Ubuntu' } }
● Key : Value● 無序集合體,以 key存取● 以 hash table實作
2010/08/09 30 minutes Python
21
File I/OFile 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
2010/08/09 30 minutes Python
22
Dynamic type?Dynamic type?
● 整數,字串是不能改的?我明明就可以改他啊!● A = 3B = Aprint A , BA = 'hello'print A , B
● Refrence(參照值 ) → object( 物件 )● 屬性是屬於物件的,而變數就是參照值● [ 'abc' , [(1, 2), ([3],4)],'def']
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 30 minutes Python 24
Let's think!為什麼縮排?
2010/08/09 30 minutes Python 25
給你三秒鐘
2010/08/09 30 minutes Python
26
給你三秒鐘給你三秒鐘 !!!!
if (x) if (y)
statement1;else statement;
else statement2;
2010/08/09 30 minutes Python 27
看完了嘛?
2010/08/09 30 minutes Python 28
縮排是 Python 的其中一重點!
2010/08/09 30 minutes Python
29
縮排縮排
● 可讀性優先 ; readability counts● 把習慣養好● 方便大家協同作業,大家的程式碼一目瞭然。
●While loopWhile loop
● while true: print "Spam"else print "Aminzai"
● while i < 5: i = i + 1 print i
● countinue break pass else
●For loopFor loop
● for i in lists: print i
● for line in open('file'):● 如果要反覆特定次數:搭配 range()
for i in range(5) print "Spam"
FunctionFunction
● def print_aminzai(): print "Aminzai"
print_aminzai()● 利用 return 回傳值● 注意:變數所存在之範圍內建>廣域>函式>區域
ObjectObject
● 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.jobaminzai.info()
ObjectObject
● class man(Person): self.sex = male
aminzai = man(‘aminzai’, ‘student’)aminzai.sexaminzai.info()
2010/08/09 30 minutes Python
35
DocumentDocument
● help()● dir()● Pydoc● 說明文件和程式碼放在一起
2010/08/09 30 minutes Python 36
2010/08/09 30 minutes Python 37
2010/08/09 30 minutes Python
38
Fire Show!!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
– http://confjoke.appspot.com/
2010/08/09 30 minutes Python
39
ResourceResource
● PyTUG:www.python.org.tw● irc.://irc.freenode.net/#python.tw● Ptt Python討論版● http://www.python.org/
2010/08/09 30 minutes Python 40
2010/08/09 30 minutes Python
41
Next TopicNext Topic
HadoopOr
My Develop Envirment