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 Factorial of Number Using Recursion
Python type()
Python Program to Find Sum of Natural Numbers Using Recursion
Python Program to Get Line Count of a File
Python *args and **kwargs
Python len()
Python Dictionary fromkeys()
Python ascii()
Python list()
Python Strings
Python classmethod()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python String center()
Python Numbers, Type Conversion and Mathematics
Python Directory and Files Management
Python enumerate()
Python Program to Access Index of a List Using for Loop
Python Program to Find HCF or GCD
Python hash()
How to get current date and time in Python?
Python Program to Transpose a Matrix
Python Program to Safely Create a Nested Directory
Python Program to Shuffle Deck of Cards
Python sleep()
Python Program to Print Hello world!
Python Program to Find the Size (Resolution) of a Image
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python String join()
Deep Learning with Python - Francois Chollet
Python String title()
Python Tuple count()
Python Program to Make a Simple Calculator