開発環境
- 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)、Test Your Knowledge: Part II Exercises、1(The basics)を解いてみる。
その他参考書籍
1(The basics)
入出力結果(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. >>> 2 ** 16 # 2の16乗 65536 >>> 2 // 5, 2 / 5 # (0, 0.4) (0, 0.4) >>> 'spam' + 'eggs' # 'spameggs' 'spameggs' >>> s='ham' >>> 'eggs ' + s # 'eggs ham' 'eggs ham' >>> s * 5 # 'hamhamhamhamham' 'hamhamhamhamham' >>> s[:0] # '' '' >>> 'green {} and {}'.format('eggs', s) # green eggs and ham' 'green eggs and ham' >>> ('x',)[0] # 'x' 'x' >>> ('x', 'y')[1] # 'y' 'y' >>> l = [1,2,3] + [4,5,6] # [1,2,3,4,5,6] >>> l [1, 2, 3, 4, 5, 6] >>> l[:] # [1,2,3,4,5,6] [1, 2, 3, 4, 5, 6] >>> l[:0] # [] [] >>> l[-2] # [5] 5 >>> l[-2:] # [5,6] [5, 6] >>> ([1,2,3] + [4,5,6])[2:4] # [3,4] [3, 4] >>> [l[2], l[3]] # [3, 4] [3, 4] >>> l.reverse(); l # [6,5,4,3,2,1] [6, 5, 4, 3, 2, 1] >>> l.sort(); l # [1,2,3,4,5,6] [1, 2, 3, 4, 5, 6] >>> l.index(4) # 3 3 >>> {'a':1, 'b':2}['b'] # 2 2 >>> d={'x':1, 'y':2, 'z':3} >>> d['w'] = 0 >>> d['x'] = d['w'] >>> d[(1,2,3)] = 4 >>> list(d.keys()) ['z', 'y', 'x', 'w', (1, 2, 3)] >>> list(d.values()) # [3, 2, 0, 0, 4] [3, 2, 0, 0, 4] >>> (1, 2, 3) in d # True True >>> [[]] [[]] >>> ['', [], (), {}, None] ['', [], (), {}, None] >>> quit() $
0 コメント:
コメントを投稿