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 strftime()
Python Program to Check If Two Strings are Anagram
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
APIs in Node.js vs Python - A Comparison
Python Iterators
Python List pop()
Python pass statement
Python RegEx
Python Tuple count()
Python Numbers, Type Conversion and Mathematics
Python String translate()
Python Generators
Python isinstance()
Python exec()
Python String find()
Python Program to Transpose a Matrix
Python break and continue
Python String isupper()
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Program to Convert Kilometers to Miles
Python open()
Python bytes()
Python Type Conversion and Type Casting
Python Deep Learning Cookbook - Indra den Bakker
Python List append()
Python Exception Handling Using try, except and finally statement
Python Program to Get the File Name From the File Path
Python String split()
Python staticmethod()
Python Program to Count the Number of Digits Present In a Number
Python Program to Find Sum of Natural Numbers Using Recursion
Python Program to Check If a String Is a Number (Float)