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 Create a Long Multiline String
Python Closures
Python any()
Python Shallow Copy and Deep Copy
Python Program to Find Numbers Divisible by Another Number
Python String islower()
Python Set intersection()
Python hasattr()
Python Program to Reverse a Number
Python String isspace()
Python String isalnum()
Python iter()
Python set()
Python Program to Check If Two Strings are Anagram
Python Program to Differentiate Between type() and isinstance()
Python Dictionary pop()
Python Generators
Python Program to Get a Substring of a String
Python Data Types
Python Program to Check If a List is Empty
Python repr()
Python Program to Transpose a Matrix
Python String rpartition()
Python Global, Local and Nonlocal variables
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Program to Check if a Key is Already Present in a Dictionary
Python String center()
Python Program to Convert Celsius To Fahrenheit
Python Set clear()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python String lower()
Python open()