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 Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python String partition()
Python String encode()
Python Program to Check If a String Is a Number (Float)
Python any()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Program Read a File Line by Line Into a List
Python staticmethod()
Python input()
Python Dictionary copy()
Python Package
Python max()
Deep Learning with Python - Francois Cholletf
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Get Current time
Python String isdigit()
Python Objects and Classes
Python Dictionary pop()
Python float()
Python Set symmetric_difference()
Python Program to Display the multiplication Table
Python String endswith()
Python Strings
Python Set clear()
Python frozenset()
Python Set difference_update()
Python Program to Find Sum of Natural Numbers Using Recursion
Python memoryview()
Python Anonymous / Lambda Function
Python List count()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Variables, Constants and Literals