Python ord() function returns an integer representing the Unicode code point of the character.
This function is commonly used in situations where you need to perform operations on the numeric representations of characters, such as in encryption algorithms or sorting algorithms.
Syntax
ord(c)
Parameter
c: It is a parameter is any character whose length is 1.
Example 1: Basic Usage
# code point of a digit
print(ord('6')) # Prints the Unicode code point of the digit '6'
# code point of uppercase alphabet
print(ord('A'))
# code point of lowercase alphabet
print(ord('x'))
# code point of special characters
print(ord('@'))
print(ord('#'))
print(ord('~'))
Output
54
65
120
64
35
126
Example 2: TypeError: ord() expected a character, but string of length 2 found
print(ord('AB'))
Output
TypeError: ord() expected a character, but string of length 2 found
Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.