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 String isprintable()
Python eval()
Python String splitlines()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python String upper()
Python String index()
Python Program to Iterate Over Dictionaries Using for Loop
Python Variables, Constants and Literals
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python String isdigit()
Python abs()
Python String format_map()
Python Set symmetric_difference()
APIs in Node.js vs Python - A Comparison
Python String center()
Python Program to Print the Fibonacci sequence
Python any()
Python divmod()
Python List extend()
Python Program to Check if a Number is Positive, Negative or 0
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Parse a String to a Float or Int
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python String swapcase()
Python Program to Safely Create a Nested Directory
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Measure the Elapsed Time in Python
Python Dictionary update()
Python Program to Get the Class Name of an Instance
Python int()
Machine Learning with Python for everyone - Mark E.Fenner
Python Get Current time