ascii () in Python

Python Methods and Functions

Syntax :


A method can only take one parameter, an object which can be a list, strings, etc. As discussed, it returns a printable representation of the object. 

 Input: ascii ("¥") Output: 'xa5' Input: ascii (" µ ") Output:' xb5' Input: ascii ("Ë") Output: ' xcb' 

We can see that in these examples all non-ASCII characters have been escaped, i.e. the encoded code is displayed using the ascii () method.


# Python ascii () illustration program

str = "G ë ê ksf? r G? ek s"

print (ascii ( str ))


 'G xeb xea ksf u03b8 r G u03b5 eks' 

This article courtesy of Chinma Lenka . If you are as Python.Engineering and would like to contribute, you can also write an article using or by posting an article contribute @ See my article appearing on the Python.Engineering homepage and help other geeks.

Please write in comments if you find anything wrong or if you'd like to share more information on the topic discussed above.

Get Solution for free from DataCamp guru