2013年2月3日日曜日

開発環境

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

その他参考書籍

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

入出力結果(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.
>>> l = [0,1,2,3]
>>> l[2] = []
>>> l
[0, 1, [], 3]
>>> l[2:3] = []
>>> l
[0, 1, 3]
>>> del l[0]
>>> l
[1, 3]
>>> del l[0:]
>>> l
[]
>>> l[1:2] = 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only assign an iterable
>>> l
[]
>>> l[1:4] = [1,2,3,4,5]
>>> l
[1, 2, 3, 4, 5]
>>> quit()
$

ちなみにJavaScriptの場合。

コード(BBEdit)

var a = [0, 1, 2, 3],
    result = a + "\n";
a[2] = [];
result += a + "\n";
a.splice(2, 1);
result += a + "\n";
delete a[0];
result += a + "\n";
$('#pre0').text(result);








						

0 コメント:

コメントを投稿