Table of Contents
In this tutorial, we will learn about the Python ord() function with the help of examples.
The ord() function returns an integer representing the Unicode character.
Example
character = 'P' # find unicode of P unicode_char = ord(character) print(unicode_char) # Output: 80
1. ord() Syntax
The syntax of ord() is:
ord(ch)
2. ord() Parameters
The ord() function takes a single parameter:
- ch – a Unicode character
3. ord() Return Value
The ord() function returns an integer representing the Unicode character.
4. Example: How ord() works in Python?
print(ord('5')) # 53
print(ord('A')) # 65
print(ord('$')) # 36
Output
53 65 36
By the way, the ord() function is the inverse of the Python chr() function.
Related posts:
Python Statement, Indentation and Comments
Python enumerate()
Python Objects and Classes
Python Object Oriented Programming
Python Tuple
Python Dictionary pop()
Python Inheritance
Python Numbers, Type Conversion and Mathematics
Python Tuple index()
Python Keywords and Identifiers
Python Program to Print all Prime Numbers in an Interval
Python Program to Delete an Element From a Dictionary
Python Set update()
Python setattr()
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Find Armstrong Number in an Interval
Python isinstance()
Python Program to Check Whether a String is Palindrome or Not
Python Program to Find HCF or GCD
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Set issuperset()
Python timestamp to datetime and vice-versa
Python RegEx
Python List reverse()
Python Dictionary popitem()
Python all()
Python Program to Illustrate Different Set Operations
Python sum()
Python String rsplit()
Python chr()
Python List sort()
Python Program to Print Colored Text to the Terminal