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 Return Multiple Values From a Function
Python compile()
Python format()
Python Program to Compute all the Permutation of the String
Python List clear()
Python frozenset()
Python String capitalize()
Python Object Oriented Programming
Python Dictionary
Python Dictionary pop()
Machine Learning with Python for everyone - Mark E.Fenner
Python bin()
Python Program to Create a Long Multiline String
Python Program to Check if a Number is Odd or Even
Python strftime()
Python Closures
Python Program to Check Armstrong Number
Python bool()
Python int()
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Operators
Python hasattr()
Python Data Structures and Algorithms - Benjamin Baka
Python hex()
Python Program to Find the Factorial of a Number
Python Program to Swap Two Variables
Python String format()
Python List reverse()
Python Program to Access Index of a List Using for Loop
Python Variables, Constants and Literals
Python String splitlines()
APIs in Node.js vs Python - A Comparison