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 Program to Access Index of a List Using for Loop
Python Dictionary values()
Python locals()
Python String isdigit()
Python Program to Check If a String Is a Number (Float)
Python Program to Display Powers of 2 Using Anonymous Function
Python Program to Print Hello world!
Python isinstance()
Python Program to Check if a Number is Odd or Even
Python String isnumeric()
Python Objects and Classes
Python String islower()
Python List extend()
Python Shallow Copy and Deep Copy
Python chr()
Python String expandtabs()
Python __import__()
Python String isupper()
Python Tuple index()
Python Program to Display the multiplication Table
Python Program to Copy a File
Python Dictionary get()
Python String rindex()
Python enumerate()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python String lower()
Python String capitalize()
Python Strings
Python bin()
Python Program to Trim Whitespace From a String
Python String rpartition()
Python min()