Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Django Girls Taipei: Python
Search
Tzu-ping Chung
May 30, 2015
Programming
1
100
Django Girls Taipei: Python
Python 教學(用於 Django Girls Taipei)
Tzu-ping Chung
May 30, 2015
Tweet
Share
More Decks by Tzu-ping Chung
See All by Tzu-ping Chung
Datasets: What it is, and how it was made
uranusjr
0
150
Let’s fix extras in Core Metadata 3.0
uranusjr
0
550
Python Packaging: Why Don’t You Just…?
uranusjr
1
230
這樣的開發環境沒問題嗎?
uranusjr
9
2.6k
Django After Web 2.0
uranusjr
3
2.1k
We Store Cheese in A Warehouse
uranusjr
1
460
The Python You Don’t Know
uranusjr
17
3.1k
Python and Asynchrony
uranusjr
0
380
Graphics on Raspberry Pi with Qt 5
uranusjr
0
96k
Other Decks in Programming
See All in Programming
Railsアプリケーションと パフォーマンスチューニング ー 秒間5万リクエストの モバイルオーダーシステムを支える事例 ー Rubyセミナー 大阪
falcon8823
5
1.1k
ご注文の差分はこちらですか? 〜 AWS CDK のいろいろな差分検出と安全なデプロイ
konokenj
2
120
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
950
新メンバーも今日から大活躍!SREが支えるスケールし続ける組織のオンボーディング
honmarkhunt
5
7.7k
LT 2025-06-30: プロダクトエンジニアの役割
yamamotok
0
790
AI Agent 時代のソフトウェア開発を支える AWS Cloud Development Kit (CDK)
konokenj
3
280
Startups on Rails in Past, Present and Future–Irina Nazarova, RailsConf 2025
irinanazarova
0
140
ソフトウェア品質を数字で捉える技術。事業成長を支えるシステム品質の マネジメント
takuya542
2
14k
技術同人誌をMCP Serverにしてみた
74th
1
660
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
190
AIともっと楽するE2Eテスト
myohei
7
2.8k
なぜ「共通化」を考え、失敗を繰り返すのか
rinchoku
1
660
Featured
See All Featured
RailsConf 2023
tenderlove
30
1.1k
Facilitating Awesome Meetings
lara
54
6.4k
A designer walks into a library…
pauljervisheath
207
24k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
Done Done
chrislema
184
16k
Building an army of robots
kneath
306
45k
The Straight Up "How To Draw Better" Workshop
denniskardys
235
140k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
700
Gamification - CAS2011
davidbonilla
81
5.4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
Transcript
Python djangogirlstaipei.herokuapp.com/tutorials/python/
(٥̫٥)א 锞㢵䭸來 Python
C:\Users\Tzu-‐ping Chung>python3 Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014,
10:38:22) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
uranusjr@ubuntu:~$ python3 Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
uranusjr:~ uranusjr$ python3 Python 3.4.1 (default, Aug 24 2014,
21:32:40) [GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-‐503.0.40)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
>>> 2 + 3 5
(٥̫٥) 5 2 + 3
>>> 4 * 5 ??? >>> 40 /
(7 -‐ 3) * 2 ??? >>> 2 ** 3 ???
>>> 'I am a Django Girl' 'I am a
Django Girl' >>> 'Hello ' + 'Django' 'Hello Django' >>> 'Django ' * 3 'Django Django Django ' >>> len('Django') 6
>>> len('Django') 6 ⴅ䒭
ⴄ䒭涸せ㶵(「鑁)
>>> len(304023) Traceback (most recent call last):
File "<stdin>", line 1, in <module> TypeError: object of type 'int' has no len()
>>> len(304023) Traceback (most recent call last):
File "<stdin>", line 1, in <module> TypeError: object of type 'int' has no len()
>>> len(str(304023)) 6
>>> str(304023) '304023' >>> int('123') 123
>>> int('Hello!') ???
>>> int('Hello!') Traceback (most recent call last):
File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: 'Hello!'
>>> pet = 'Kitty' >>> 岣䠐鸍儗⦪湫陻㐻չ♶剙պ㔐⫄湫〪剙 랾랾䪾隵侶涸⧩鏣饯⢵կ
'Kitty' pet
>>> pet = 'Kitty' >>> pet 'Kitty'
>>> len(pet) 5 >>> seven = 7 >>> six = 6 >>> answer = seven * six >>> answer 42
>>> pet = 'Kitty' >>> pat ???
(٥̫٥) 'Kitty' pet 'Kitty' pet
(խ̫)? ???? pat 'Kitty' pet
>>> pet = 'Kitty' >>> pat Traceback (most
recent call last): File "<stdin>", line 1, in <module> NameError: name 'pat' is not defined
>>> [] [] >>> lottery = [59, 42,
30, 19, 12, 3] >>> len(lottery) 6
>>> lottery[0] 59 >>> lottery[1] 42
>>> lottery[-‐1] ??? >>> lottery[1000] ???
>>> lottery = [59, 42, 30, 19, 12, 3]
>>> print(lottery[1000]) Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: list index out of range
>>> lottery = [59, 42, 30, 19, 12, 3]
>>> lottery[1] = 22 >>> lottery [59, 22, 30, 19, 12, 3]
>>> {} {} >>> my_information = {
... 'name': 'Pusheen the Cat', ... 'country': 'USA', ... 'favorite_numbers': [42, 105]} >>> len(my_information) 3
>>> my_information['name'] Pusheen the Cat >>> my_information['age']
???
>>> my_information['age'] Traceback (most recent call last):
File "<stdin>", line 1, in <module> KeyError: 'age'
>>> my_information {'name': 'Pusheen the Cat', 'country': 'USA',
'favorite_numbers': [42, 105]} >>> my_information['color'] = 'gray' >>> len(my_information) 4 >>> del my_information['farovite_numbers'] >>> my_information {'name': 'Pusheen the Cat', 'country': 'USA', 'color': 'gray'}
>>> my_information['name'] = 'Pusheen' >>> my_information {'name': 'Pusheen',
'country': 'USA', 'color': 'gray'}
>>> 5 > 2 True >>> 3 <
1 False >>> 5 > 2 * 3 False >>> 1 == 1 True
>>> 6 >= 12 / 2 True >>>
3 <= 2 False >>> 6 > 2 and 2 < 3 True >>> 3 > 2 and 2 < 1 False >>> 3 > 2 or 2 < 1 True
>>> 'Sherlock' > 'John' ??? >>> 1 <
'Django' ???
>>> 'Sherlock' > 'John' True >>> 1 <
'Django' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unorderable types: int() < str()
• NameError • ValueError • IndexError •
KeyError • TypeError
>>> is_cool = True >>> is_cool True
>>> can_go_home = 2 > 5 >>> can_go_home False
>>> True and True ??? >>> False and
True ??? >>> True or 1 == 1 ??? >>> 1 != 2 ???
>>> pet = 'Pusheen' >>> pet 'Pusheen'
>>> print(pet) Pusheen
(٥̫٥) 'Pusheen' QFU酭僽➊ 랃 'Pusheen' pet
(٥̫٥)א ⽫ⴀQFU涸Ⰹ㺂 Pusheen 'Pusheen' pet
(٥̫٥) 6 TJY酭僽➊랃 6 six
(٥̫٥)א ⽫ⴀTJY涸Ⰹ㺂 6 six 6
None
$ python3 my_program.py 'I am a Django Girl'
㛂遤鸏❉䭸⟂ (٥̫٥)א 穡卓
if 3 > 2:
$ python3 my_program.py File "my_program.py", line 2
^ SyntaxError: unexpected EOF while parsing
if 3 > 2: print('It works!')
㔋⦐瑠涯 侄箺銲岣䠐♧♴㷷㆞涸箟鰿㐻剣鏣㹀䧭 tab with spaces ㄤ tab size = 4
$ python3 my_program.py It works!
if 2 > 5: print('2 >
5') else: print('2 <= 5') $ python3 my_program.py 2 <= 5
if 2 > 5: print('2 >
5') elif 2 < 5: print('2 < 5') else: print('2 == 5') $ python3 my_program.py 2 < 5
def hi(): print('Hi there!')
print('How are you?') $ python3 my_program.py
def hi(): print('Hi there!')
print('How are you?') hi() $ python3 my_program.py Hi there! How are you?
def hi(name): print('Hi' + name +'!')
print('How are you?') hi()
$ python3 my_program.py Traceback (most recent call last):
File "my_program.py", line 4, in hi() TypeError: hi() missing 1 required positional argument: 'name'
def hi(name): print('Hi' + name +'!')
print('How are you?') hi('Pusheen') $ python3 my_program.py Hi Pusheen! How are you?
㋿
class Cat: def meow(self):
print('Meow!')
class Cat: def meow(self):
print('Meow!') pusheen = Cat() pusheen.meow() $ python3 cat.py Meow!
class Cat: def __init__(self, name):
self.name = name def meow(self): print(self.name + ' Meow!') pusheen = Cat() pusheen.meow()
$ python3 cat.py Traceback (most recent call last):
File "cat.py", line 8, in pusheen = Cat() TypeError: __init__() missing 1 required positional argument: 'name'
class Cat: def __init__(self, name):
self.name = name def meow(self): print(self.name + ' Meow!') pusheen = Cat() pusheen.meow()
class Cat: def __init__(self, name):
self.name = name def meow(self): print(self.name + ' Meow!') pusheen = Cat('Pusheen') pusheen.meow() $ python3 cat.py Pusheen Meow!
class Cat: def __init__(self, name):
self.name = name def meow(self): print(self.name + ' Meow!') pusheen = Cat('Pusheen') pusheen.meow() print(pusheen) $ python3 cat.py Pusheen Meow! <__main__.Cat object at 0x1006f15c0>
class Cat: def __init__(self, name):
self.name = name def __str__(self): return 'Cat: ' + self.name def meow(self): print(self.name + ' Meow!') pusheen = Cat('Pusheen') pusheen.meow() print(pusheen)
$ python3 cat.py Pusheen Meow! Cat: Pusheen
def hi(name): print('Hi ' + name
+ '!') girls = ['Michelle', 'Ola', 'you'] for name in girls: hi(name) print('Next girl')
$ python3 say_hi.py Hi Michelle! Next girl
Hi Ola! Next girl Hi you! Next girl
class Cat: def __init__(self, name):
self.name = name def __str__(self): return 'Cat: ' + self.name def meow(self): print(self.name + ' Meow!') pet.py
import pet cats = [
pet.Cat('Kitty'), pet.Cat('Pusheen'), pet.Cat('Doraemon'), ] for cat in cats: cat.meow() say_meow.py
$ ls pet.py say_meow.py $ python3
say_meow.py Kitty Meow! Pusheen Meow! Doraemon Meow!
# 䪾 pet 垷穈Ⰵ import pet # 䪾
pet 酬涸 Cat 겲ⴽⰅ from pet import Cat
姻鋊邍爚䒭 3FHVMBS&YQSFTTJPO
〵⻍䋑⥌纏⼦匡➋騟贫垜 넞꧆䋑뛥㚆⼦⚥姻㔋騟贫 㾓匌簖惐䊝ꔩꆄꤰ遳贫 倞畾簖畾⻍䋑⯕僈Ⱉ騟匌♧媯贫
〵⻍䋑⥌纏⼦匡➋騟贫垜 넞꧆䋑뛥㚆⼦⚥姻㔋騟贫 㾓匌簖惐䊝ꔩꆄꤰ遳贫 倞畾簖畾⻍䋑⯕僈Ⱉ騟匌♧媯贫
import re addresses = [
'台北市信義區松仁路7號8樓', '高雄市鹽埕區中正四路274號', '屏東縣潮州鎮金陵街31號', '新竹縣竹北市光明六路東一段183號', ] for addr in addresses: print(re.search(r'\w+市', addr)) address.py
import re addresses = [
'台北市信義區松仁路7號8樓', '高雄市鹽埕區中正四路274號', '屏東縣潮州鎮金陵街31號', '新竹縣竹北市光明六路東一段183號', ] for addr in addresses: print(re.search(r'\w+市', addr)) address.py
\w+䋐 ♧⦐㶶 涸匌銯 ♧⦐⟃♳ չ䋑պ鸏⦐㶶
for addr in addresses: match =
re.search(r'(?P<city>\w+市)', addr) if match: print(match.group('city')) address.py $ python3 address.py 台北市 高雄市 新竹縣竹北市
for addr in addresses: match =
re.search(r'(?P<city>\w{2}市)', addr) if match: print(match.group('city')) address.py $ python3 address.py 台北市 高雄市 竹北市
for addr in addresses: match =
re.search(r'^(?P<city>\w{2}市)', addr) if match: print(match.group('city')) address.py $ python3 address.py 台北市 高雄市
〵⻍䋑⥌纏⼦匡➋騟贫垜 넞꧆䋑뛥㚆⼦⚥姻㔋騟贫 㾓匌簖惐䊝ꔩꆄꤰ遳贫 倞畾簖畾⻍䋑⯕僈Ⱉ騟匌♧媯贫
〵⻍䋑⥌纏⼦匡➋騟贫垜 넞꧆䋑뛥㚆⼦⚥姻㔋騟贫 㾓匌簖惐䊝ꔩꆄꤰ遳贫 倞畾簖畾⻍䋑⯕僈Ⱉ騟匌♧媯贫
for addr in addresses: match =
re.search( r'(?P<no>\d+號)$', addr, ) if match: print(match.group('no')) address.py $ python3 address.py 274號 31號 183號
for addr in addresses: match =
re.search( r'(?P<no>\d+號(\d+樓)?)$', addr, ) if match: print(match.group('no')) address.py $ python3 address.py 7號8樓 274號 31號 183號
^ 걧 $ 穡㽵 \w ♧⦐㶶 \d ♧⦐䬘⠭侸㶶 + 涸匌銯♧⦐⟃♳
{num} 涸匌銯剤num⦐ ? 涸匌銯ꨫ䧴♧⦐ ( ... ) 䪾匌銯穉ざ㖈♧饱 (?P<name> ...) 䪾匌銯穉ざ㖈♧饱⚛《そ䧭name
‧ӹ,:*:‧\(ӟ)/‧:*‧°ӹ*