開発環境
- 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 Ⅱ.(Types and Operations)、Test Your Knowledge: Part II Exercises 10.(Nesting)を解いてみる。
その他参考書籍
- Pythonチュートリアル 第2版
- Python クックブック 第2版 (原書(最新版))
- Programming Python
- Python Pocket Reference (Pocket Reference (O'Reilly))
10.(Nesting)
コード(BBEdit)
sample10.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
personal_info = dict(name=('first', 'middle', 'last'),
name1=dict(first='first name', middle='middle name',
last='last name'),
age=10, job='python',
address='Japan', email='example@example.com',
phone=1234567890)
for key, value in personal_info.items():
if key == 'name1':
for k, v in value.items():
print('{0:10s}: {1}'.format(k, v))
else:
print('{0:10s}: {1}'.format(key, value))
入出力結果(Terminal, IPython)
$ ./sample10.py
email : example@example.com
address : Japan
name : ('first', 'middle', 'last')
phone : 1234567890
job : python
first : first name
middle : middle name
last : last name
age : 10
$
0 コメント:
コメントを投稿