開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
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.
- append method
- sort method
- reverse method
- extend method
- insert method
- pop method
- remove method
- 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 コメント:
コメントを投稿