artist "tage asenartist encode("latin " 'tage \xc \xe nartist encode("cp " 'tage \ fs\ nartist encode("utf " 'tage \xc \ \xc \xa nartist encode("utf " '\xff\xfet\ \ \ \ \ \xc \ \ \xe \ \ before an opening quote signifies bytes literal rather than string literal as conveniencewhen creating bytes literals we can use mixture of printable ascii characters and hexadecimal escapes we cannot encode tage asen' name using the ascii encoding because it does not have the character or any accented charactersso attempting to do so will result in unicodeencodeerror exception being raised the latin- encoding (also known as iso- - is an -bit encoding that has all the necessary characters for this name on the other handartist erno'bank would be less fortunate since the 'character is not latin- character and so could not be successfully encoded both names can be successfully encoded using unicode encodingsof course noticethoughthat for utf- the first two bytes are the byte order mark--these are used by the decoding function to detect whether the data is bigor little-endian so that it can adapt accordingly it is worth noting couple more points about the str encode(method the first argument (the encoding nameis case-insensitiveand hyphens and underscores in the name are treated as equivalentso "us-asciiand "us_asciiare considered the same there are also many aliases--for example"latin""latin ""latin_ ""iso- - ""cp "and some others are all "latin- the method can also accept an optional second argument which is used to tell it how to handle errors for examplewe can encode any string into ascii if we pass second argument of "ignoreor "replace"--at the price of losing dataof course--or losslessly if we use "backslashreplacewhich replaces non-ascii characters with \ \uand \ escapes for exampleartist encode("ascii""ignore"will produce 'tage snand artist encode("ascii""replace"will produce 'tage ? ? 'whereas artist encode("ascii""backslashreplace"will produce 'tage \xc \xe (we can also get an ascii string using "{ ! }format(artist)which produces 'tage \xc \xe nthe complement of str encode(is bytes decode((and bytearray decode()which returns string with the bytes decoded using the given encoding for exampleprint( "tage \xc \ \xc \xa ndecode("utf ")tage asen