bytearray( 'yamlmno'len( replace('xy''sp'this works in typeerrortype str doesn' support the buffer api replace( 'xy' 'sp'bytearray( 'spamlmno' bytearray( 'xyamlmno' bytearray( 'xyamlmnoxyamlmnoxyamlmnoxyamlmno'python string types summary finallyby way of summarythe following examples demonstrate how bytes and byte array objects are sequences of intsand str objects are sequences of charactersbinary versus text 'spamlist( [ is same as in bytearray( 'xyamlmno'list( [ 'spamlist( [' '' '' '' 'although all three python string types can contain character values and support many of the same operationsagainyou should alwaysuse str for textual data use bytes for binary data use bytearray for binary data you wish to change in place related tools such as filesthe next section' topicoften make the choice for you using text and binary files this section expands on the impact of python ' string model on the file processing basics introduced earlier in the book as mentioned earlierthe mode in which you open file is crucial--it determines which object type you will use to represent the file' using text and binary files