Ascii () function in Python

In Python, the ascii () function returns a string containing the representation of the object that can print. It ignores non-ASCII values ​​in the string using x, u or U.

In Python, the ascii () function returns a string containing the representation of the object that can print. It ignores non-ASCII values ​​in the string using x, u or U.

Syntax of ascii () function in Python:

 ascii(object) 

Parameters of ascii () function:

The function ascii () has only one object parameter (such as string, list, .).

What value does the function ascii () return?

It returns a string containing the representation of the object that is printable.

For example, ö will be converted to xf6, √ will become u221a, Š will become u0152.

Values ​​other than ASCII will be replaced by x, u or U.

Example of ascii () function:

In the example below, we will try some ASCII characters and see what the ascii () function will return:

 danhsach = ['Python','PŸTHON','√', 'ö','Pythön', 'Š', 'Œ','Ž',10, '©'] 
print(ascii(danhsach))

After running the above program, we get the following output:

 ['Python', 'Pu0178THON', 'u221a', 'xf6', 'Pythxf6n', 'u0160', 'u0152', 'u017d', 10, 'xa9'] 

You can see a list of built-in Python functions and don't forget to do Python exercises to reinforce your knowledge.

4.8 ★ | 4 Vote