Python 3 reference · Built-in Functions

Python ord() Function

Return the Unicode code point (an integer) of a single character, such as ord('A') giving 65. The inverse of chr().

Python 3 Since 3.0

Syntax

ord(c)

Parameters

ParameterDescription
c A string of exactly one character (or a bytes/bytearray of length 1).

Return value

An int.

Examples

Characters to numbersTry it yourself
print(ord("A"), ord("a"), ord("€"))
print(chr(ord("A") + 2))

Output

65 97 8364
C
Every character of a wordTry it yourself
word = "Python"
print([ord(c) for c in word])
print(sum(ord(c) for c in word) % 100)  # a toy checksum

Output

[80, 121, 116, 104, 111, 110]
42

Good to know

ord() needs exactly one character: ord("ab") and ord("") raise TypeError.

Version history

VersionChange
Python 3.0Added