if you are encoding text and don' know which encoding to useit is best to use the utf- encoding utf- is able to represent any unicode character in modern softwareit is de facto standard encoding to ensure documents in any language--or even multiple languages--can be exchanged the various other possible encodings are useful for legacy documents or in regions that still use different character sets by default the utf- encoding uses one byte to represent ascii and other common charactersand up to four bytes for more complex characters utf- is special because it is backwards-compatible with asciiany ascii document encoded using utf- will be identical to the original ascii document can never remember whether to use encode or decode to convert from binary bytes to unicode always wished these methods were named "to_binaryand "from_binaryinstead if you have the same problemtry mentally replacing the word "codewith "binary""enbinaryand "debinaryare pretty close to "to_binaryand "from_binaryi have saved lot of time by not looking up the method help files since devising this mnemonic mutable byte strings the bytes typelike stris immutable we can use index and slice notation on bytes object and search for particular sequence of bytesbut we can' extend or modify them this can be very inconvenient when dealing with /oas it is often necessary to buffer incoming or outgoing bytes until they are ready to be sent for exampleif we are receiving data from socketit may take several recv calls before we have received an entire message this is where the bytearray built-in comes in this type behaves something like listexcept it only holds bytes the constructor for the class can accept bytes object to initialize it the extend method can be used to append another bytes object to the existing array (for examplewhen more data comes from socket or other / channelslice notation can be used on bytearray to modify the item inline for examplethis code constructs bytearray from bytes object and then replaces two bytesb bytearray( "abcdefgh" [ : "\ \xa print(bthe output looks like thisbytearray( 'abcd\ \xa gh'