2014年8月24日日曜日

開発環境

Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅱ.(Types and Operations)、Test Your Knowledge: Part II Exercises 1.(The basics)解いてみる。

その他参考書籍

1.(The basics)

入出力結果(Terminal, IPython)

$ ipython
Python 3.4.1 (default, May 21 2014, 01:39:38) 
Type "copyright", "credits" or "license" for more information.

IPython 2.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: 2 ** 16 # 65536
Out[1]: 65536

In [2]: 2 / 5 # 0.4
Out[2]: 0.4

In [3]: 2 / 5.0 # 0.4
Out[3]: 0.4

In [4]: 'spam' + 'eggs' # 'spameggs'
Out[4]: 'spameggs'

In [5]: s = 'ham'

In [6]: 'eggs' + s # 'eggsham'
Out[6]: 'eggsham'

In [7]: s * 5 # 'hamhamhamhamham'
Out[7]: 'hamhamhamhamham'

In [8]: s[:0] # ''
Out[8]: ''

In [9]: 'green %s and %s' % ('eggs', s) # 'green eggs and ham'
Out[9]: 'green eggs and ham'

In [10]: 'green {0} and {1}'.format('eggs', s) # 'green eggs and ham'
Out[10]: 'green eggs and ham'

In [11]: ('x',)[0] # 'x'
Out[11]: 'x'

In [12]: ('x', 'y')[1] # 'y'
Out[12]: 'y'

In [13]: L = [1,2,3] + [4,5,6]

In [14]: L # [1,2,3,4,5,6]
Out[14]: [1, 2, 3, 4, 5, 6]

In [15]: L[:] # [1,2,3,4,5,6]
Out[15]: [1, 2, 3, 4, 5, 6]

In [16]: L[:0] # []
Out[16]: []

In [17]: L[-2] # 5
Out[17]: 5

In [18]: L[-2:] # [5, 6]
Out[18]: [5, 6]

In [19]: ([1,2,3] + [4,5,6])[2:4] # [3,4]
Out[19]: [3, 4]

In [20]: [L[2], L[3]] # [3, 4]
Out[20]: [3, 4]

In [21]: L.reverse()

In [22]: L # [6,5,4,3,2,1]
Out[22]: [6, 5, 4, 3, 2, 1]

In [23]: L.sort()

In [24]: L # [1,2,3,4,5,6]
Out[24]: [1, 2, 3, 4, 5, 6]

In [25]: L.index(4) # 3
Out[25]: 3

In [26]: {'a':1, 'b':2}['b'] # 2
Out[26]: 2

In [27]: d = {'x':1, 'y':2, 'z':3}

In [28]: d['w'] = 0

In [29]: d['x'] + d['w'] # 1
Out[29]: 1

In [30]: d[(1,2,3)] = 4

In [31]: list(d.keys()) # ['x', 'y', 'z', 'w', (1,2,3)] (順序不明)
Out[31]: ['x', 'w', 'z', 'y', (1, 2, 3)]

In [32]: list(d.values) # [1,2,3,0,4] (順序不明)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-0a0a369cecd5> in <module>()
----> 1 list(d.values) # [1,2,3,0,4] (順序不明)

TypeError: 'builtin_function_or_method' object is not iterable

In [33]: list(d.values()) # [1,2,3,0,4] (順序不明)
Out[33]: [1, 0, 3, 2, 4]

In [34]: (1, 2, 3) in d # True
Out[34]: True

In [35]: [[]] # [[]]
Out[35]: [[]]

In [36]: ["", [], (), {}, None] # ['', [], (), {}, None]
Out[36]: ['', [], (), {}, None]

In [37]: quit()
$

0 コメント:

コメントを投稿