The ord() function in Python returns an integer representing the Unicode code point of a given character. It’s the inverse of the chr()
function.
Basic Usage
code_point = ord('A')
print(code_point) # Output: 65
Working with Characters
Convert characters to their ASCII values:
print(ord('a')) # Output: 97
print(ord('0')) # Output: 48
Conclusion
The ord()
function is useful for character encoding and decoding tasks. It helps in understanding the numerical representation of characters.