English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The ascii() method returns a string containing the printable representation of the object. It uses \x, \u, or \U escape characters to escape non-ASCII characters in the string.
The syntax of ascii() is:
ascii(object)
The ascii() method takes an object (such as:string,listetc.).
It returns a string containing the printable representation of the object.
For example, ö can be changed to \xf6n, √ can be changed to \u221a
Non-ASCII characters in strings are escaped using \x, \u, or \U.
normalText = 'Python is interesting' print(ascii(normalText)) otherText = 'Pythön is interesting' print(ascii(otherText)) print('Pyth\xf6n is interesting')
When running the program, the output is:
'Python is interesting' 'Pyth\xf6n is interesting' Pythön is interesting
randomList = ['Python', 'Pythön', 5] print(ascii(randomList))
When running the program, the output is:
['Python', 'Pyth\xf6n', 5]