2012年10月20日土曜日

開発環境

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

その他参考書籍

3.

リストを上書きするには、

  1. インデクシング(L[index])
  2. スライシング(L[:]
  3. L.append(object)
  4. L.extend(list)
  5. L.insert(index, object)
  6. L.remove(object)
  7. L.pop(index)
  8. L.reverse()
  9. L.sort()
  10. 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 コメント:

コメントを投稿