Thứ Tư, Tháng Hai 12, 2025
spot_img
HomeStudyascii() function in Python

ascii() function in Python

 

In Python, the ascii() function returns a string containing printable object representations. It ignores non-ASCII values ​​in strings using \x, \u or \U.

Syntax of the ascii() function in Python

ascii(object)

Parameters of the ascii() function:

Jaw ascii() there is only one parameter object. object (like string, list,…).

What value does the ascii() function return?

The ascii() function will return a string containing printable representations of the object.

For example: ö will be converted into \xf6, will become \u221a, Š will become \u0152.

Non-ASCII values ​​will be replaced with \x, \u or \U.

Example of the ascii() function

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

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

After running the above program we receive the following output:

[‘Python’, ‘P\u0178THON’, ‘\u221a’, ‘\xf6’, ‘Pyth\xf6n’, ‘\u0160’, ‘\u0152’, ‘\u017d’, 10, ‘\xa9’]

You can see the list of built-in Python functions and don’t forget to do the Python exercises to further consolidate your knowledge.

Xem thêm  C++ exercises with solutions (sample code)
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments