開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs(Text Editor)
- プログラミング言語: Python
『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のVI部(クラスとクラスのコーディング (基礎))の24章(Pythonでのクラスのコーディング (詳細))の練習問題2を解いてみる。
その他参考書籍
2.
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3 #-*- coding: utf-8 -*- # 反復処理をサポートするのに使用するのは # __iter__または、__getitem__ class A: def __init__(self, stop): self.stop = stop def __getitem__(self, index): if index < 0 or self.stop <= index: raise IndexError return index + index for x in A(10): print(x) print([x * x for x in A(10)]) for x in map(lambda x : x + 1, A(10)): print(x)
入出力結果(Terminal)
$ ./sample.py 0 2 4 6 8 10 12 14 16 18 [0, 4, 16, 36, 64, 100, 144, 196, 256, 324] 1 3 5 7 9 11 13 15 17 19 $
0 コメント:
コメントを投稿