Python ord() function


(Sponsors) Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!


The ord() function (short of ordinal) returns an integer representing the character passed to it. For ASCII characters, the returned value is 7-bit ASCII code, and for Unicode characters, it refers to the Unicode code point.

Its syntax is as follows:

ParameterDescription
c c is the string character string.

Here is an example:

To convert an integer returned by ord()  back to its character equivalent we use chr() function.


Other Tutorials (Sponsors)

This site generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!


Leave a Reply

Your email address will not be published. Required fields are marked *