Ascii() in python


ASCII is abbreviated from of American Standard Code for Information Interchange. It is a character encoding standard. For example the ASCII value of English alphabet A is 65. Python provides this function to get the printable representation of an object. It takes one parameter which is an object that can be a list, strings, tuple etc. The output of the function is the hex representation. The non-ascii characters can be escaped using \x, \u or \U escapes.

Syntax

The syntax is −

Syntax:
ascii(object)

Example

Printing strings with individual characters and multiple characters.

# Individual Characters
print(ascii("Ω"))
print(ascii("θ"))
# A string int multiple characters
print(ascii("TΨtΦrial"))

Output

Running the above code gives us the following result −

'\u03a9'
'\u03b8'
'T\u03a8t\u03a6rial'

Updated on: 07-Aug-2019

752 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements