開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7)のⅡ部(ビルトインオブジェクト)、4章(Pythonのビルトインオブジェクト)の練習問題、1.を解いてみる。
その他参考書籍
1.
コード(BBEdit)
module1.py
#!/usr/bin/env python3.3 #-*- coding: utf-8 -*- for t, v in [('int', 10), ('float', 1.2), ('string', 'python'), ('list', [1,2]), ('dictionary', {'a':1, 'b':2}), ('tuple', (1, 'a')), ('file', open('sample.py')), ('set', {1,2,3,4,5})]: print('{0} {1} {2}'.format(t, v, type(v)))
入出力結果(Terminal)
$ ./sample.py int 10 <class 'int'> float 1.2 <class 'float'> string python <class 'str'> list [1, 2] <class 'list'> dictionary {'b': 2, 'a': 1} <class 'dict'> tuple (1, 'a') <class 'tuple'> file <_io.TextIOWrapper name='sample.py' mode='r' encoding='UTF-8'> <class '_io.TextIOWrapper'> set {1, 2, 3, 4, 5} <class 'set'> $
0 コメント:
コメントを投稿