Full name
ord
Library
Built-in
Syntax
ord(c)
Description
The ord function returns the Unicode code of the character passed as an argument.
This function is the inverse of the chr function.
Parameters
- c: character whose Unicode code we want to know
Examples
In this example we obtained the Unicode code of different characters:
print(ord("a"))
print(ord("A"))
print(ord("ñ"))
print(ord("€"))
The argument must be a single character. If it is a text string of a greater length, the function returns an error of type TypeError:
print(ord("ab"))
The same happens if the text string included as an argument has zero length:
print(ord(""))