2014年2月9日日曜日

開発環境

Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART II.(Types and Operations)、CHAPTER 4(Introducing Python Object Types)、Test Your Knowledge: Quiz 6を解いてみる。

その他参考書籍

Test Your Knowledge: Quiz 6

"polymorphism"とは、型によって振る舞いが変わる演算子等のこと。具体例として、「+」演算子は数値なら通常の足し算、文字列、リストだと文字列、リストの連結、になる。「*」演算子は数値だと通常の掛け算、文字列、リストだと文字列、リストの繰り返しになる。

入出力結果(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.
>>> 5 + 10
15
>>> 'python' + ' programmer'
'python programmer'
>>> [1,2,3] + [4,5,6]
[1, 2, 3, 4, 5, 6]
>>> [1,2] + [3,4]
[1, 2, 3, 4]
>>> 5 * 10
50
>>> 'python' * 10
'pythonpythonpythonpythonpythonpythonpythonpythonpythonpython'
>>> [1,2] * 10
[1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
>>> quit()
$

0 コメント:

コメントを投稿