Tutorials  Articles  Notifications  Login  Signup


VS

Vishal Saxena

SDE 1 at Amazon March 29, 2020, 7:08 p.m. ⋅ 1036 views

How to get the ASCII value of a character in Python


Function ord()  is used to get int ASCII value of any character in Python.

>>> ord('a')
97

To get back the character from any given int function chr() is used.

>>> chr(97)
'a'
>>> chr(ord('a') + 3)
'd'
>>>

If you are using UTF-8 charcters, you need to pass it a unicode otherwise, it will throw a TypeError error.

>>> ord(u'あ')
12354

 



HackerFriend Logo

Join the community of 1 Lakh+ Developers

Create a free account and get access to tutorials, jobs, hackathons, developer events and neatly written articles.


Create a free account