ascii () in Python

Python Methods and Functions

Syntax :

ascii(object)

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. 
Examples:

 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.

Example:

# Python ascii () illustration program

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

print (ascii ( str ))

Output:

 '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 contribute.python.engineering or by posting an article contribute @ python.engineering. 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