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 max()
Python setattr()
Python Iterators
Python globals()
Python repr()
Python String rpartition()
Python File I/O Operation
Python String isprintable()
Python Directory and Files Management
Python strftime()
Python Dictionary popitem()
Python String index()
Python Namespace and Scope
Python open()
Python Set discard()
Python format()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python len()
Python ascii()
Python Program to Convert String to Datetime
Python String islower()
Python String lstrip()
Python Program to Convert Decimal to Binary Using Recursion
Python String isalpha()
Python Program to Sort Words in Alphabetic Order
Python Program to Sort a Dictionary by Value
Python Program to Iterate Over Dictionaries Using for Loop
Python String ljust()
Python oct()
Python Dictionary items()
Python Program to Iterate Through Two Lists in Parallel
Python map()