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 Deep Learning Cookbook - Indra den Bakker
Python Numbers, Type Conversion and Mathematics
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Function Arguments
Python Program to Check if a Number is Positive, Negative or 0
Python String isalpha()
Python Program to Swap Two Variables
Python set()
Python isinstance()
Python Variables, Constants and Literals
Python bytearray()
Python Program to Create a Countdown Timer
Python String strip()
Python timestamp to datetime and vice-versa
Python Set issuperset()
Python Program to Find the Sum of Natural Numbers
Python Program to Merge Two Dictionaries
Python List sort()
Python Program to Compute the Power of a Number
Python Program to Make a Simple Calculator
Python String expandtabs()
Python String format()
Python classmethod()
Python Functions
Python List pop()
Python String swapcase()
Python String isdigit()
Python bytes()
Deep Learning with Python - Francois Cholletf
Python Set symmetric_difference_update()
Python Program to Check If a String Is a Number (Float)
Python id()