Skip to content

Instantly share code, notes, and snippets.

@yubessy
Last active August 29, 2015 14:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yubessy/11208290 to your computer and use it in GitHub Desktop.
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