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 pow()
Python Operator Overloading
Python exec()
Python Decorators
Python hash()
Python type()
Python Closures
Python Set issuperset()
Python Program to Get the Class Name of an Instance
Python Program to Merge Two Dictionaries
Python Program to Calculate the Area of a Triangle
Python super()
Python Program to Iterate Through Two Lists in Parallel
Python Program to Swap Two Variables
Python Dictionary update()
Python sorted()
Python int()
Python Set isdisjoint()
Python Program to Solve Quadratic Equation
Python Set issubset()
Python Program to Check if a Number is Positive, Negative or 0
Python Program to Make a Simple Calculator
Python Program to Print Colored Text to the Terminal
Python sleep()
Python Program to Make a Flattened List from Nested List
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Deep Learning Cookbook - Indra den Bakker
Python max()
Node.js vs Python for Backend Development
Python List extend()
Python List
Python Directory and Files Management