開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅲ.(Statements and Syntax)、Chapter 14.(Iterations and Comprehensions)、Test Your Knowledge: Quiz 1.を解いてみる。
その他参考書籍
- Pythonチュートリアル 第2版
- Python クックブック 第2版 (原書(最新版))
- Programming Python
- Python Pocket Reference (Pocket Reference (O'Reilly))
Test Your Knowledge: Quiz 1.
コード(BBEdit)
sample1.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
l = [1, 2, 3, 4, 5]
for n in l:
print(n)
# 明示的に
i = iter(l)
while True:
try:
print(i.__next__())
except StopIteration as err:
import sys
print(sys.exc_info())
break
入出力結果(Terminal, IPython)
$ ./sample1.py 1 2 3 4 5 1 2 3 4 5 (<class 'StopIteration'>, StopIteration(), <traceback object at 0x102007d48>) $
0 コメント:
コメントを投稿