開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの無料機能制限版、light版)
- Script言語: Python
『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のII部(ビルトインオブジェクト)の8章(リストとディクショナリ)の練習問題2を解いてみる。
その他参考書籍
3.
リストを上書きするには、
- インデクシング(L[index])
- スライシング(L[:]
- L.append(object)
- L.extend(list)
- L.insert(index, object)
- L.remove(object)
- L.pop(index)
- L.reverse()
- L.sort()
- L.clear()
の方法がある。
対話型セッションでの入出力結果(Terminal)
$ python3.3 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=[1,2,3,4,5] >>> l.reverse() >>> l [5, 4, 3, 2, 1] >>> l.sort() >>> l [1, 2, 3, 4, 5] >>> l.append(6) >>> l [1, 2, 3, 4, 5, 6] >>> l.extend([7,8,9]) >>> l [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l.insert(2,0) >>> l [1, 2, 0, 3, 4, 5, 6, 7, 8, 9] >>> l.remove(0) >>> l [1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l.pop(1) 2 >>> l [1, 3, 4, 5, 6, 7, 8, 9] >>> l.clear() >>> l [] >>> l.extend([1,2,3,4,5]) >>> l[1]=0 >>> l [1, 0, 3, 4, 5] >>> l[2:4]=[10,11] >>> l [1, 0, 10, 11, 5] >>> quit() $
0 コメント:
コメントを投稿