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:
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Dictionary popitem()
Python zip()
Python Set intersection()
Python Set difference_update()
Python String center()
Python Objects and Classes
Python Custom Exceptions
Python id()
Python globals()
Python String lstrip()
Python int()
Python Program to Convert Decimal to Binary Using Recursion
Python Set isdisjoint()
Python Global, Local and Nonlocal variables
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Statement, Indentation and Comments
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python compile()
Python Multiple Inheritance
Python Program to Merge Mails
Python sleep()
Python open()
Python File I/O Operation
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python *args and **kwargs
Python Program to Check if a Key is Already Present in a Dictionary
Python List insert()
Python locals()
Python List index()
Python Program to Get File Creation and Modification Date
Python String isupper()