Skip to content
Related Articles

Related Articles

Improve Article
ascii() in Python
  • Last Updated : 06 Nov, 2020

ascii() returns a string containing a printable representation of an object and escape the non-ASCII characters in the string using \x, \u or \U escapes

Syntax: ascii(object)

The method can take only one parameter, an object that can be a list, strings, etc. As already discussed, it returns a printable representation of an object. 
 

Examples: 

Input : ascii("¥")
Output : '\xa5'

Input : ascii("µ")
Output : '\xb5'

Input : ascii("Ë")
Output : '\xcb'


We see that in these examples, all the non-ASCII characters have been escaped, i.e, their encoded code gets displayed by using the ascii() method.
Example: 
 

Python3




# Python program to illustrate ascii()
str = "G ë ê k s f ? r G ? e k s"
print (ascii(str))

Output: 
 



'G \xeb \xea k s f ? r G ? e k s'

This article is contributed by Chinmoy Lenka. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
 

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :