開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅱ.(Types and Operations)、Chapter 4.(Introducing Python Object Types)、Test Your Knowledge: Quiz 3.を解いてみる。
その他参考書籍
Test Your Knowledge: Quiz 3.
不変性をもつオブジェクトであるということ。(変更できない。変更したい場合は、新しいオブジェクトを作成することにより、擬似的に変更することになる。)
immutable
- strings
- numbers
- tuples
コード(BBEdit)
sample3.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
s = 'python'
try:
s[0] = 'a'
except Exception as err:
print(type(err), err)
t = (1, 2)
try:
t[0] = 10
except Exception as err:
print(type(err), err)
入出力結果(Terminal, IPython)
$ ./sample3.py <class 'TypeError'> 'str' object does not support item assignment <class 'TypeError'> 'tuple' object does not support item assignment $
0 コメント:
コメントを投稿