Created
July 8, 2015 03:56
-
-
Save arthuralvim/9d3c0bf59e8860ba395b to your computer and use it in GitHub Desktop.
About unicode and str in Python.
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
# unicode => human readable format | |
uni_text = u'café' | |
print type(uni_text) | |
print isinstance(uni_text, str) | |
print len(uni_text) | |
uni_str_convert = uni_text.encode('UTF-8') | |
# str => bytes | |
str_text = 'café' | |
print type(str_text) | |
print isinstance(str_text, unicode) | |
print len(str_text) | |
str_uni_convert = str_text.decode('UTF-8') | |
# comparisons | |
print uni_str_convert == uni_text | |
print uni_str_convert == str_text | |
print str_uni_convert == uni_text | |
print str_uni_convert == str_text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment