開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅱ.(Types and Operations)、Chapter 4.(Introducing Python Object Types)、Test Your Knowledge: Quiz 4.を解いてみる。
その他参考書籍
Test Your Knowledge: Quiz 4.
- strings
- list
- tuples
- range
- …
コード(BBEdit)
sample4.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- s = 'python' l = ['a', 'b', 'c', 'd'] t = ('a', 'b', 'c', 'd') r = range(5) for x in [s, l, t, r]: print(type(x)) # indexing print(x[1]) # slicing print(x[:]) # iterable for y in x: print(y, end=' ') print()
入出力結果(Terminal, IPython)
$ ./sample4.py <class 'str'> y python p y t h o n <class 'list'> b ['a', 'b', 'c', 'd'] a b c d <class 'tuple'> b ('a', 'b', 'c', 'd') a b c d <class 'range'> 1 range(0, 5) 0 1 2 3 4 $
0 コメント:
コメントを投稿