2012年7月8日日曜日

開発環境

『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のIV部(関数)のまとめ演習1(簡単な関数)を解いてみる。

1.

入出力結果(Terminal)

$ python
Python 3.2.3 (default, Apr 18 2012, 20:17:30) 
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.12)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(x):
...     print(x)
... 
>>> f("Hello, Python!")
Hello, Python!
>>> f(10)
10
>>> f([1,2,3,4,5])
[1, 2, 3, 4, 5]
>>> f({'a':1,'b':2,'c':3,'d':4,'e':5})
{'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4}
>>> f((1,2,3,4,5))
(1, 2, 3, 4, 5)
>>> f()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() takes exactly 1 argument (0 given)
>>> f(1,2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() takes exactly 1 positional argument (2 given)
>>> quit()
$

0 コメント:

コメントを投稿