開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART II.(Types and Operations)、CHAPTER 4(Introducing Python Object Types)、Test Your Knowledge: Quiz 4を解いてみる。
その他参考書籍
Test Your Knowledge: Quiz 4
sequenceは順序づけられた並びのデータ型のことで、インデクシング、スライシング等が使える。sequenceに当てはまる具体的な型は文字列、リスト、タプル等。
実際に文字列、リスト、タプルでインデクシング、スライシングを使ってみる。
入出力結果(Terminal)
$ python3 Python 3.3.3 (default, Dec 2 2013, 01:40:21) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> s="python" >>> l=['a', 'b', 'c', 'd', 'e'] >>> t=('a', 'b', 'c', 'd', 'e') >>> s[0] 'p' >>> s[1] 'y' >>> l[0] 'a' >>> l[1] 'b' >>> s[1:4] 'yth' >>> s[1:] 'ython' >>> s[:2] 'py' >>> s[::2] 'pto' >>> s[1:-2] 'yth' >>> l[1:3] ['b', 'c'] >>> l[1:] ['b', 'c', 'd', 'e'] >>> l[::2] ['a', 'c', 'e'] >>> l[1:-2] ['b', 'c'] >>> t[0] 'a' >>> t[1:] ('b', 'c', 'd', 'e') >>> t[1:3] ('b', 'c') >>> t[::2] ('a', 'c', 'e') >>> t[1:-2] ('b', 'c') >>> t[:] ('a', 'b', 'c', 'd', 'e') >>> quit() $
0 コメント:
コメントを投稿