Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1.  
  2. # unicode => human readable format
  3. uni_text = u'café'
  4. print type(uni_text)
  5. print isinstance(uni_text, str)
  6. print len(uni_text)
  7. uni_str_convert = uni_text.encode('UTF-8')
  8.  
  9. # str => bytes
  10. str_text = 'café'
  11. print type(str_text)
  12. print isinstance(str_text, unicode)
  13. print len(str_text)
  14. str_uni_convert = str_text.decode('UTF-8')
  15.  
  16. # comparisons
  17. print uni_str_convert == uni_text
  18. print uni_str_convert == str_text
  19.  
  20. print str_uni_convert == uni_text
  21. print str_uni_convert == str_text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement