In this tutorial we will learn about the python ascii() method and its uses.
What is Python ascii() Method?
The ascii() method will return a readable version of a string containing a printable representation of an object.
The ascii() method will replace non-ASCII like å with escape characters like \x and \u.
The syntax of ascii() is as follows.
Python ascii() Parameter
The ascii() method will have a single parameter as an object like String, List, Tuple, Dictionary, etc.
Let’s see some examples of ascii() method.
Example 1: How to use ascii() method in the list.
Example 2: using ascii() method with strings.
The output will be as follow:
As you can see, all the non-ascii values are replaced by escape characters.
Rules of ascii() method
- It will return a readable string representation of an object.
- It will not return anything when we use an integer as an object.