2013年4月29日月曜日

開発環境

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

その他参考書籍

3.(インデクシング、スライシングとdelステートメント)

コード(BBEdit)

sample.py

#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-

l = [1,2,3,4]
l[2] = []
print(l) # [1,2,[],4]
l[2:3] = []
print(l) # [1,2,4]
del l[0]
print(l) # [2,4]
del l[0:]
print(l) # []
try:
    l[1:2] = 1
except Exception as err:
    print(type(err), err, err.args)

入出力結果(Terminal)

$ ./sample.py
[1, 2, [], 4]
[1, 2, 4]
[2, 4]
[]
<class 'TypeError'> can only assign an iterable ('can only assign an iterable',)
$

0 コメント:

コメントを投稿