Skip to content

Instantly share code, notes, and snippets.

@yubessy
Last active Aug 29, 2015
Embed
What would you like to do?
Python2のstr/unicodeとencode/decode ref: http://qiita.com/yubessy/items/9e13af05a295bbb59c25
>>> 'あいう'
'\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86'
>>> 'あ'[0]
'\xe3'
>>> 'あ'[1]
'\x81'
>>> 'あ'[2]
'\x82'
>>> 'あ'[3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range
>>> len('あいう')
9
>>> u'あいう'
u'\u3042\u3044\u3046'
>>> u'あ'[0]
u'\u3042'
>>> u'あ'[1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range
>>> len(u'あいう')
3
>>> isinstance(u'あいう', unicode)
True
>>> isinstance('あいう', str)
True
>>> isinstance('あいう', unicode)
False
>>> isinstance(u'あいう', str)
False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment