p.28 set型
そういえばset型って使ったことがないや.試してみるべきだな.(p.128でも触れるらし)
>>> se = set((1,2,3,4,5,6)) >>> se set([1, 2, 3, 4, 5, 6]) >>> se.pop() 1 >>> se set([2, 3, 4, 5, 6])
インデクシングできないところなどリストに似てリストに非ずのようだ.
同 整数同士の割り算は切り捨てではない
>>> -1/2 -1
p.44 ユニコード文字列を使う
よくわかってないんだけど,とりあえず端末の出力を載せておこう.
cmd.exe
>>> ustr = u"日本語" >>> ustr u'\u65e5\u672c\u8a9e' >>> print ustr 日本語 >>>
IDLE 1.1.3
>>> ustr = u"日本語"
>>> print ustr
“ú–{Œê
>>> print ustr.encode('utf-8')
ツ禿コツ本ツ古ェ
>>>
>>> print ustr.encode('mbcs')
?u?{?e
>>> print ustr.encode('shift-jis')
Traceback (most recent call last):
File "<pyshell#5>", line 1, in -toplevel-
print ustr.encode('shift-jis')
UnicodeError: Shift_JIS encoding error: invalid character \x93
>>> print ustr.encode('iso-8859-1')
日本語
IPython 0.7.2 (空白行を端折ってます.)
In [1]: ustr = u"日本語"
In [2]: print ustr
---------------------------------------------------------------------------
exceptions.UnicodeError Traceback (most recent call last)
C:\Python24\<ipython console>
UnicodeError: MS932 encoding error: invalid character \x93
In [3]: print ustr.encode('mbcs')
?u?{?e
In [4]: print ustr.encode('utf-8')
ツ禿コツ本ツ古ェ
In [5]: print ustr.encode('shift-jis')
---------------------------------------------------------------------------
exceptions.UnicodeError Traceback (most recent call last)
C:\Python24\<ipython console>
UnicodeError: Shift_JIS encoding error: invalid character \x93
In [6]: print ustr.encode('iso-8859-1')
日本語