Head First Programming
A learner's guide to programming
using the Python language
( O'Reilly Media; )
David Griffiths (著) Paul Barry (著)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Head First Programming A learner's guide to programming using the Python language (David Griffiths(著)、Paul Barry(著)、 O'Reilly Media; )のChapter 2(textual data: Every string has its place)、Sharpen your pencil(p.43, 45)を解いてみる。
Sharpen your pencil(p.43, 45)
コード(BBEdit)
sample43.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- s = 'But where is Waldo?' print(s[5:9] == 'here') print(s[10:12] == 'is') print(s[13:18] == 'Waldo')
入出力結果(Terminal)
$ ./sample43.py True True True $
コード(BBEdit)
sample45.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- import urllib.request page = urllib.request.urlopen('http://beans-r-us.appspot.com/prices.html') text = page.read().decode('utf8') # 65 61 13 47 44 price = text[234:238] print(price)
入出力結果(Terminal)
$ ./sample45.py 6.22 $
0 コメント:
コメントを投稿