Python built-in Method - ord()

The ord() function is a built-in Python method that returns the Unicode code point of a single character string. The Unicode code point is an integer that represents the position of the character in the Unicode character set.

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

re‮ef‬r to:theitroad.com
ord(c)
  • c: A single character string.

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

>>> ch = 'A'
>>> code = ord(ch)
>>> print(code)
65

In the above example, we have a single character string 'A'. We pass this string as an argument to the ord() function, which returns the Unicode code point of the character as an integer 65. This is because the Unicode code point for the character 'A' is 65.

We can also use the ord() function with other characters and Unicode symbols:

>>> ch = '€'
>>> code = ord(ch)
>>> print(code)
8364

In the above example, we have a single character string '€', which is the Euro symbol. We pass this string as an argument to the ord() function, which returns the Unicode code point of the symbol as an integer 8364.

The ord() function is useful for working with Unicode characters and strings in Python, especially when dealing with non-ASCII characters and symbols. It is often used in combination with the chr() function, which returns the character string for a given Unicode code point.