string
Python 2
  • a sequence of code points, immutable
  • Python keep characters as unicode in memory
  • String read from a file is byte string, need to be decoded to unicode
  • Output unicode to a file, need to encode to byte string
  • Print a unicode on console, it is encoded to byte string automatically by default encoding method
  • ord, convert a string to its unicode code point
  • unichr, convert an integer into a Unicode string
  • type 'str' represents byte string in Python 2, type 'unicode' represent unicode
  • Python 3
  • type 'str' represents unicode in Python 3, type 'bytes' represent byte string