開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs(Text Editor)
- プログラミング言語: Python
『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7)のII部(ビルトインオブジェクト)のまとめ演習2.(インデクシングとスライシング)を解いてみる。
その他参考書籍
2.(インデクシングとスライシング)
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-
L = [1, 2, 3, 4]
try:
print(L[4])
except Exception as err:
print(type(err), err, err.args)
print(L[-1000:100]) # [1,2,3,4]
print(L[3:1]) # []
L[3:1] = ['?']
print(L) # [1, 2, 3, '?', 4]
入出力結果(Terminal)
$ ./sample.py
<class 'IndexError'> list index out of range ('list index out of range',)
[1, 2, 3, 4]
[]
[1, 2, 3, '?', 4]
$
0 コメント:
コメントを投稿