English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Il metodo ascii() restituisce una stringa che contiene la rappresentazione stampabile dell'oggetto. Usa i segni di escape \x, \u o \U per escapare i caratteri non ASCII all'interno della stringa.
La sintassi di ascii() è:
ascii(object)
Il metodo ascii() accetta un oggetto (ad esempio:Stringa,Elencoecc.).
Restituisce una stringa che contiene la rappresentazione stampabile dell'oggetto.
Ad esempio, ö diventa \xf6n, √ diventa \u221a
I caratteri non ASCII all'interno di una stringa possono essere escapati utilizzando \x, \u o \U.
normalText = 'Python è interessante' print(ascii(normalText)) otherText = 'Pythön è interessante' print(ascii(otherText)) print('Pythön è interessante')
Quando si esegue questo programma, l'output è:
'Python è interessante' 'Pythön è interessante' Pythön è interessante
randomList = ['Python', 'Pythön', 5] print(ascii(randomList))
Quando si esegue questo programma, l'output è:
['Python', 'Pythön', 5]