2014年2月20日木曜日

開発環境

Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART II.(Types and Operations)、Test Your Knowledge: Part II Exercises、6.(Dictionary indexing)を解いてみる。

その他参考書籍

6.(Dictionary indexing)

入出力結果(Terminal)

$ python3
Python 3.3.4 (default, Feb 10 2014, 22:06:52) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> d={'a':1,'b':2,'c':3}
>>> d['d'] # エラー
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'd'
>>> d['d'] = 'spam'
>>> d # {'a':1,'b':2,'c':3,'d':'spam'}
{'c': 3, 'b': 2, 'a': 1, 'd': 'spam'}
>>> l=['a','b','c']
>>> l[3] # エラー
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> l[3]='d' # エラー
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list assignment index out of range
>>> quit()
$

0 コメント:

コメントを投稿