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 dict()
Python Dictionary setdefault()
Python List index()
Python Numbers, Type Conversion and Mathematics
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python compile()
Python Program to Compute the Power of a Number
Python Type Conversion and Type Casting
Python Iterators
Python Program to Transpose a Matrix
Python Program to Display the multiplication Table
Python String translate()
Python Machine Learning - Sebastian Raschka
Python len()
Python zip()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Tuple count()
How to get current date and time in Python?
Python Program Read a File Line by Line Into a List
Python round()
APIs in Node.js vs Python - A Comparison
Python Program to Get the Last Element of the List
Python Dictionary clear()
Python complex()
Python Program to Capitalize the First Character of a String
Python Program to Extract Extension From the File Name
Python String capitalize()
Python Generators
Python Program to Find Armstrong Number in an Interval
Python hasattr()
Python Program to Merge Mails
Python Program to Swap Two Variables