Python ord()
Python ord() builtin function returns an integer representing the given Unicode character.
ord() has the inverse functionality of chr() builtin function.
In this tutorial, we will learn about the syntax of Python ord() function, and learn how to use this function with the help of examples.
Syntax
The syntax of ord() function is
ord(ch)
where
Parameter | Required/Optional | Description |
---|---|---|
ch | Required | A string with only one Unicode character. |
Returns
The function returns an int object.
Example
In this example, we will take a string with single character, say 'm'
, and find the integer value for the Unicode character m
.
Call ord() function and pass the string 'm'
as argument. The function returns an integer.
Python Program
ch = 'm'
result = ord(ch)
print(result)
Output
109
Conclusion
In this Python Tutorial, we have learnt the syntax of Python ord() builtin function, and also learned how to use this function, with the help of Python example programs.