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.

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy