開発環境
- 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 2.を解いてみる。
その他参考書籍
- Pythonチュートリアル 第2版
- Python クックブック 第2版 (原書(最新版))
- Programming Python
- Python Pocket Reference (Pocket Reference (O'Reilly))
Test Your Knowledge: Quiz 2.
コード(BBEdit)
sample2.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
print('for loop')
l1 = []
for x in range(10):
l1.append(x ** 2)
print(l1)
print('list comprehension')
l2 = [x ** 2 for x in range(10)]
print(l2)
入出力結果(Terminal, IPython)
$ ./sample2.py for loop [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] list comprehension [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] $
0 コメント:
コメントを投稿