開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- Script言語: Python
『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のII部(ビルトインオブジェクト)のまとめ演習5.(ディクショナリのキー)を解いてみる。
その他参考書籍
5.(ディクショナリのキー)
入出力結果(Terminal)
$ python Python 3.3.0 (default, Sep 29 2012, 08:16:08) [GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> D={} >>> D[1] = 'a' >>> D # {1:'a'} {1: 'a'} >>> D[2] = 'b' >>> D # {1:'a',2:'b'} {1: 'a', 2: 'b'} >>> D[(1,2,3)] = 'c' #ディクショナリのキーには不変性のオブジェクトを使える >>> D {1: 'a', 2: 'b', (1, 2, 3): 'c'} >>> quit() $
ちなみにJavaScriptの場合。
コード(BBEdit)
var d = {}, result = ""; d[1] = 'a'; d[2] = 'b'; d[[1,2,3]] = 'c'; for (p in d) { result += p + ": " + d[p] + "\n"; } $('#pre0').text(result);
0 コメント:
コメントを投稿