2014年8月14日木曜日

開発環境

Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅱ.(Types and Operations)、Chapter 8.(Lists and Dictionaries)、Test Your Knowledge: Quiz 3.を解いてみる。

その他参考書籍

Test Your Knowledge: Quiz 3.

  1. append method
  2. sort method
  3. reverse method
  4. extend method
  5. insert method
  6. pop method
  7. remove method
  8. clear method

コード(BBEdit)

sample3.py

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

l = list(range(10))
print(l)

l.append(-10)
print(l)

l.sort()
print(l)

l.reverse()
print(l)

l.extend(['a', 'b', 'c', 'd'])
print(l)

l.insert(5, (1,2))
print(l)

l.pop()
print(l)

l.remove('a')
print(l)

l.clear()
print(l)

入出力結果(Terminal, IPython)

$ ./sample3.py
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -10]
[-10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -10]
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -10, 'a', 'b', 'c', 'd']
[9, 8, 7, 6, 5, (1, 2), 4, 3, 2, 1, 0, -10, 'a', 'b', 'c', 'd']
[9, 8, 7, 6, 5, (1, 2), 4, 3, 2, 1, 0, -10, 'a', 'b', 'c']
[9, 8, 7, 6, 5, (1, 2), 4, 3, 2, 1, 0, -10, 'b', 'c']
[]
$

0 コメント:

コメントを投稿