Tutorials  Articles  Notifications  Login  Signup


Vishal Saxena

SDE 1 at Amazon March 29, 2020, 7:08 p.m. ⋅ 1081 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')

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

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

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

>>> ord(u'あ')


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