2012年5月19日土曜日

開発環境

『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のII部(ビルトインオブジェクト)の6章(ダイナミックな型付け)の練習問題を解いてみる。

1.

1行目: "spam"

2行目: "spam"

3行目: "spam"

ということで値は変化しない。

2.

1行目: ["spam"]

2行目: ["spam"]

3行目: ["shrubbery"]

3.

1行目: ["spam"]

2行目: ["spam"]

3行目: ["spam"]

ということで変化しない。

確認

入出力結果(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.
>>> a="spam"
>>> a
'spam'
>>> b=a
>>> a
'spam'
>>> b="shrubbery"
>>> a
'spam'
>>> a=["spam"]
>>> a
['spam']
>>> b=a
>>> a
['spam']
>>> b[0]="shrubbery"
>>> a
['shrubbery']
>>> a=["spam"]
>>> b=a[:]
>>> a
['spam']
>>> b[0]="shrubbery"
>>> a
['spam']
>>> quit()
$

0 コメント:

コメントを投稿