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 Sort a Dictionary by Value
Python List pop()
Python Function Arguments
Python Program to Extract Extension From the File Name
Python Program to Transpose a Matrix
Python Machine Learning - Sebastian Raschka
Python sorted()
Python Program to Compute the Power of a Number
Python Program to Trim Whitespace From a String
Python Program to Print Hello world!
Python Program to Check the File Size
Python enumerate()
Python hex()
Python Dictionary
Python Set difference()
Python Set clear()
Python Program to Print Colored Text to the Terminal
Python Dictionary fromkeys()
Python int()
Python Program to Check If a String Is a Number (Float)
Python Program to Reverse a Number
Python exec()
Python String rstrip()
Python type()
Python Dictionary keys()
Python Statement, Indentation and Comments
Python slice()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Copy a File
Python Program to Get the Last Element of the List
Python zip()
Python Program to Differentiate Between type() and isinstance()