Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python ascii() function returns printable representation of any object, like strings, lists and tuples etc. The function replaces any non-ascii characters with escape characters (\x, \u and \U).

Syntax

ascii(object)

Parameters

object Required. Specify object like strings, lists and tuples etc.

Example:

In the below example, ascii function returns printable version of objects. Non-ascii characters are replaced with escape characters like '£' is converted into '\xa3' and 'α' is converted into '\u03b1'.

print(ascii('£'))

print(ascii('α'))

print(ascii('α Coding Skills'))

The output of the above code will be:

'\xa3'

'\u03b1'

'\u03b1 Coding Skills'

Example:

In the below example, ascii function returns printable version of a list called MyList. Each element of the list is converted into printable version as described above.

MyList = ['Python', 'Pythön', 'Pythoñ']
print(ascii(MyList))

The output of the above code will be:

['Python', 'Pyth\xf6n', 'Pytho\xf1']

❮ Python Built-in Functions