python string objects originate when you call built-in function such as str or bytesread file created by calling open (described in the next section)or code literal syntax in your script for the lattera new literal formb'xxx(and equivalentlyb'xxx'is used to create bytes objects in xand you may create bytearray objects by calling the bytearray functionwith variety of possible arguments more formallyin all the current string literal forms--'xxx'"xxx"and triplequoted blocks--generate stradding or just before any of them creates bytes instead this new bbytes literal is similar in form to the rraw string used to suppress backslash escapes consider the followingrun in xc:\codec:\python \python 'spams 'eggs bytes literal make bytes object ( -bit bytes str literal makes unicode text string type( )type( ( 'spams 'eggsbytessequence of intprints as character string the bytes object is actually sequence of short integersthough it prints its content as characters whenever possibleb[ ] [ indexing returns an int for bytesstr for str ( ' ' [ :] [ :slicing makes another bytes or str object ( 'pam''ggs'list( )list( ([ ][' '' '' '' ']bytes is really -bit small ints the bytes object is also immutablejust like str (though bytearraydescribed lateris not)you cannot assign strbytesor integer to an offset of bytes object [ 'xboth are immutable typeerror'bytesobject does not support item assignment [ 'xtypeerror'strobject does not support item assignment finallynote that the bytes literal' or prefix also works for any string literal formincluding triple-quoted blocksthough you get back string of raw bytes that may or may not map to charactersbytes prefix works on singledoubletriple quotesraw ""xxxx yyyy "" '\nxxxx\nyyyy\ncoding basic strings