The official Python documentation explains ord(c)
ord(c):
Given a string representing one Unicode character, return an integer representing the Unicode code point of that character. For example, ord('a') returns the integer 97 and ord('€') (Euro sign) returns 8364. This is the inverse of chr().
It does not specify the meaning of ord
, google searches are not helpful.
What's the origin of it?
The ord() function returns the number representing the unicode code of a specified character.
Ord is a function (short of ordinal) which returns an integer representing the character passed to it. It means every character has some integer value; these characters cannot be read by computer directly; it first converts every character into the ASCII code.
Python ord() and chr() are built-in functions. They are used to convert a character to an int and vice versa. Python ord() and chr() functions are exactly opposite of each other.
The chr() function returns the character that represents the specified unicode.
It stands for "ordinal".
The earliest use of ord
that I remember was in Pascal. There, ord()
returned the ordinal value of its argument. For characters this was defined as the ASCII code.
The same convention was also used in Modula-2.
Later, Python (as well as PHP, some dialects of SQL etc) followed this convention, except that these days they're more likely to use Unicode rather than ASCII.
It could well be that the origins of the term (and the function name) go back further than Pascal.
Return the integer ordinal of a one-character string.
I took this from ord.doc in python command line. ord meaning ordinal of a one character.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With