Python Function Reference

ord

Get the Unicode code point of a character.

Python 3.13
ord(c)

Parameters

cstr
A string of exactly one character.

Return value

An integer, the code point of the character; raises TypeError for a string of another length.

Examples

Code of a Latin letter

Python 3.13
print(ord('A'))
65

Code of a Cyrillic letter

Python 3.13
print(ord('я'))
1103

Details

The inverse function is chr. Latin letter codes go in a row, so ord(c) - ord("a") gives the position of a lowercase letter in the alphabet, starting from 0. To get the codes of all characters of a string, use [ord(c) for c in text].

See also