'spam'spamencode('utf ' 'spam'spamencode('utf ' '\xff\xfes\ \ \ \ characters may be or bytes in memory encoded to bytes in utf- in files but encoded to bytes in utf- both and also support the bytearray string type we met earlierwhich is essentially bytes string ( str in xthat supports most of the list object' in-place mutable change operations both and also support coding non-ascii characters with \ hexadecimal and short \ and long \ unicode escapesas well as file-wide encodings declared in program source files here' our non-ascii character coded three ways in (add leading "uand say "printto see the same in )'sp\xc \ \ 'spaaamwhat these values mean and how they are used differs between text stringswhich are the normal string in and unicode in xand byte stringswhich are bytes in and the normal string in all these escapes can be used to embed actual unicode code-point ordinal-value integers in text strings by contrastbyte strings use only \ hexadecimal escapes to embed the encoded form of textnot its decoded code point values--encoded bytes are the same as code pointsonly for some encodings and characters'\ ''\ encode('latin ') '\xa decode('latin '('ps' '\xa ''ps'as notable differencepython allows its normal and unicode strings to be mixed in expressions as long as the normal string is all asciiin contrastpython has tighter model that never allows its normal and byte strings to mix without explicit conversionu'xb'yu' 'yworks in (where is optional and ignoredworks in xu'xyu'xb'yu' 'yfails in (where is optional and ignoredworks in 'xy'xb'ydecode('xencode( 'yworks in if decode bytes to str'xyworks in if encode str to bytesb'xyapart from these string typesunicode processing mostly reduces to transferring text data to and from files--text is encoded to bytes when stored in fileand decoded into characters ( code pointswhen read back into memory once it is loadedwe usually process text as strings in decoded form only because of this modelthoughfiles are also content-specific in xtext files implement named encodings and accept and return str stringsbut binary files instead deal in strings