らんだむな記憶

blogというものを体験してみようか!的なー

python3って

文字列を扱う上では圧倒的に楽。rubyならもっと楽な気もするけど...。

[python2.7.6]

>>> ord("a")
97
>>> ord(u"a")
97
>>> ord("あ")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ord() expected a character, but string of length 3 found
>>> ord(u"あ")
12354
>>> ord("ø")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ord() expected a character, but string of length 2 found
>>> ord(u"ø")
248

[python3.5.1]

>>> ord("a")
97
>>> ord(u"a")
97
>>> ord("あ")
12354
>>> ord(u"あ")
12354
>>> ord("ø")
248
>>> ord(u"ø")
248