La méthode ascii () renvoie une chaîne contenant une représentation imprimable d'un objet. Il échappe les caractères non ASCII de la chaîne en utilisant les échappements x, u ou U.
La syntaxe de ascii()
est:
ascii (objet)
Paramètres ascii ()
ascii()
La méthode prend un objet (comme: des chaînes, une liste, etc.).
Valeur renvoyée par ascii ()
Il renvoie une chaîne contenant une représentation imprimable d'un objet.
Par exemple, ö
est changé en xf6n
, √
est changé enu221a
Les caractères non ASCII de la chaîne sont échappés à l'aide de x
, u
ou U
.
Exemple 1: Comment fonctionne la méthode ascii ()?
normalText = 'Python is interesting' print(ascii(normalText)) otherText = 'Pythön is interesting' print(ascii(otherText)) print('Pythxf6n is interesting')
Production
'Python est intéressant' 'Pyth xf6n est intéressant' Pythön est intéressant
Plus d'exemples
randomList = ('Python', 'Pythön', 5) print(ascii(randomList))
Production
('Python', 'Pyth xf6n', 5)