Python2のstr/unicodeとencode/decode ref: http://qiita.com/yubessy/items/9e13af05a295bbb59c25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 'あいう' | |
'\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 'あ'[0] | |
'\xe3' | |
>>> 'あ'[1] | |
'\x81' | |
>>> 'あ'[2] | |
'\x82' | |
>>> 'あ'[3] | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
IndexError: string index out of range |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> len('あいう') | |
9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> u'あいう' | |
u'\u3042\u3044\u3046' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> u'あ'[0] | |
u'\u3042' | |
>>> u'あ'[1] | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
IndexError: string index out of range |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> len(u'あいう') | |
3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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