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.
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.
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.
'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 email@example.com. 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.
- Converting an image to ASCII image in Python
- Map function and Dictionary in Python to sum ASCII values
- Python | ASCII art using pyfiglet module
- Python | Check for ASCII string
- Python | Ways to convert list of ASCII value to string
- Python | Convert String list to ascii values
- Generate simple ASCII tables using prettytable in Python
- Python - Sort Strings by Maximum ASCII value
- Python - Filter Strings within ASCII range
- Program to find the largest and smallest ASCII valued characters in a string
- Count of alphabets having ASCII value less than and greater than k
- Program to implement ASCII lookup table
- Program to print ASCII Value of a character
- Convert the ASCII value sentence to its equivalent string
- Longest string in non-decreasing order of ASCII code and in arithmetic progression
- Average of ASCII values of characters of a given string
- Minimize ASCII values sum after removing all occurrences of one character
- Check if a string contains only alphabets in Java using ASCII values
- Program to find the product of ASCII values of characters in a string
- Count and Print the alphabets having ASCII value in the range [l, r]
Improved By : code_24x7