ord() Function in Function

Python ord() Function

In Python, the ord() function is a built-in function that returns the Unicode code point for a given Unicode character (a string of length 1). Unicode is a character encoding standard that assigns a unique numeric value (code point) to each character in almost all writing systems used in the world.

The syntax of the ord() function is as follows:

ord(character)

Parameters:

  • character: A Unicode character (a string of length 1) for which you want to find the Unicode code point.

Return value:

  • An integer representing the Unicode code point of the given character.

Here's an example of using the ord() function:

char1 = 'A'
char2 = 'a'
char3 = '€'

code_point1 = ord(char1)
code_point2 = ord(char2)
code_point3 = ord(char3)

print(f"The Unicode code point of {char1} is {code_point1}")
print(f"The Unicode code point of {char2} is {code_point2}")
print(f"The Unicode code point of {char3} is {code_point3}")

Output:

The Unicode code point of A is 65
The Unicode code point of a is 97
The Unicode code point of € is 8364

As you can see, the ord() function returns the corresponding integer values for the characters 'A', 'a', and '€', which represent their Unicode code points.