2012年5月28日月曜日

開発環境

『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のII部(ビルトインオブジェクト)のまとめ演習6(ディクショナリのインデクシング)を解いてみる。

6.

ディクショナリで存在しないキーを指定してインデクシングを行うとエラーになる。

入出力結果(Terminal)

$ python
Python 3.2.3 (default, Apr 18 2012, 20:17:30) 
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.12)] 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'
>>> L=[1,2,3]
>>> L[4]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> D['d']=4
>>> D
{'a': 1, 'c': 3, 'b': 2, 'd': 4}
>>> L[3]=4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list assignment index out of range
>>> n=10
>>> n
10
>>> quit()
$

0 コメント:

コメントを投稿