the text of your script filespython uses the utf- encoding by defaultbut it allows you to change this to support arbitrary character sets by including comment that names your desired encoding the comment must be of this form and must appear as either the first or second line in your script in either python or -*codinglatin- -*when comment of this form is presentpython will recognize strings represented natively in the given encoding this means you can edit your script file in text editor that accepts and displays accented and other non-ascii characters correctlyand python will decode them correctly in your string literals for examplenotice how the comment at the top of the following filetext pyallows latin- characters to be embedded in stringswhich are themselves embedded in the script file' text-*codinglatin- -*any of the following string literal forms work in latin- changing the encoding above to either ascii or utf- failsbecause the xc and xe in mystr are not valid in either mystr 'aabecmystr ' \ \ cmystr 'achr( xc 'bchr( xe 'cimport sys print('default encoding:'sys getdefaultencoding()for astr in mystr mystr mystr print('{ }strlen={ }format(astrlen(astr))end=''bytes astr encode(bytes astr encode('latin- '#bytes astr encode('ascii'per default utf- bytes for non-ascii one byte per char ascii failsoutside range print('byteslen ={ }byteslen ={ }format(len(bytes )len(bytes ))when runthis script produces the following outputgivingfor each of three coding techniquesthe stringits lengthand the lengths of its utf- and latin- encoded byte string forms :\codec:\python \python text py default encodingutf- aabecstrlen= byteslen = byteslen = aabecstrlen= byteslen = byteslen = aabecstrlen= byteslen = byteslen = since many programmers are likely to fall back on the standard utf- encodingi'll defer to python' standard manual set for more details on this option and other advanced unicode support topicssuch as properties and character name escapes in strings ' omitting here for this let' take quick look at the new byte string object types in python xbefore moving on to its file and tool changes unicode and byte strings