'spamu[ 'slist( [ ' ' ' ' ' ' ' 'as we sawfor compatibility this form works in and later toobut it simply makes normal str there (the is ignoredstring type conversions although python allowed str and unicode type objects to be mixed in expressions (when the str contained only -bit ascii text) draws much sharper distinction --str and bytes type objects never mix automatically in expressions and never are converted to one another automatically when passed to functions function that expects an argument to be str object won' generally accept bytesand vice versa because of thispython basically requires that you commit to one type or the otheror perform manualexplicit conversions when neededstr encode(and bytes(sencodingtranslate string to its raw bytes form and create an encoded bytes from decoded str in the process bytes decode(and str(bencodingtranslate raw bytes into its string form and create decoded str from an encoded bytes in the process these encode and decode methods (as well as file objectsdescribed in the next sectionuse either default encoding for your platform or an explicitly passed-in encoding name for examplein python xs 'eggss encode( 'eggsbytes(sencoding='ascii' 'eggsb 'spamb decode('spamstr(bencoding='ascii''spamstr->bytesencode text into raw bytes str->bytesalternative bytes->strdecode raw bytes into text bytes->stralternative two cautions here first of allyour platform' default encoding is available in the sys modulebut the encoding argument to bytes is not optionaleven though it is in str encode (and bytes decodesecondalthough calls to str do not require the encoding argument like bytes doesleaving it off in str calls does not mean that it defaults--insteada str call without an encoding returns the bytes object' print stringnot its str converted form (this is usually not what you'll want!assuming and are still as in the prior listingcoding basic strings