ord()
Published May 26, 2023
Contribute to Docs
The ord()
function returns the integer that represents the Unicode character argument. It is the inverse function of chr()
which provides the Unicode character for the integer passed.
Syntax
ord(char)
The function takes a character argument char
and returns the integer value that represents it in Unicode.
Example
The example below demonstrates how to provide an argument to ord()
and print the result.
print(ord('H'))
This produces the output:
72
Codebyte Example
In the example below, the function ord()
is used on each character in the string word
. Each character is printed alongside the integer value that represents it.
Note: Letters ‘C’ and ‘c’ do not return the same integer. This is because uppercase and lowercase letters are represented by different integers in Unicode.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours