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 Find the Largest Among Three Numbers
Python Exception Handling Using try, except and finally statement
Python del Statement
Python compile()
Python list()
Python String isupper()
Python Matrices and NumPy Arrays
Python Variables, Constants and Literals
Python List clear()
Python Closures
Python List count()
Python String istitle()
Python bytearray()
Python Keywords and Identifiers
Python Program to Check If a String Is a Number (Float)
Python String isalpha()
Python Program to Get a Substring of a String
Python Set difference()
Deep Learning with Python - Francois Chollet
Python Operator Overloading
Python String isdigit()
Python Program to Measure the Elapsed Time in Python
Python Program to Check the File Size
Python String strip()
Python filter()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python oct()
Python List Comprehension
Python chr()
Python Program to Create Pyramid Patterns
Python Program to Convert String to Datetime
Python staticmethod()