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 String endswith()
Python Program to Check Prime Number
Python Program to Access Index of a List Using for Loop
Python String expandtabs()
Python oct()
Python String istitle()
Python List
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Dictionary update()
Python Program to Multiply Two Matrices
Python String isspace()
Python String isidentifier()
Python Program to Make a Flattened List from Nested List
Python Program to Create a Countdown Timer
Python hasattr()
Python sum()
Python filter()
Python String isprintable()
Python Operator Overloading
Python Program to Find HCF or GCD
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Get the Last Element of the List
Python tuple()
Python String startswith()
Python Program to Check If a String Is a Number (Float)
Python Shallow Copy and Deep Copy
How to get current date and time in Python?
Python getattr()
Python vars()
Python type()
Python Set remove()
Python Set intersection()