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 Check If Two Strings are Anagram
Python Generators
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Set clear()
Python delattr()
Machine Learning with Python for everyone - Mark E.Fenner
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python float()
Python Set update()
Python memoryview()
Python Set isdisjoint()
Python Type Conversion and Type Casting
Python Tuple index()
Python String isnumeric()
Deep Learning with Python - Francois Cholletf
Python String endswith()
Python String lstrip()
Python Program to Convert Two Lists Into a Dictionary
Python complex()
Python callable()
Python if...else Statement
Python *args and **kwargs
Python Dictionary get()
Python range()
Python hasattr()
Python Set discard()
Python type()
Python Program to Find Sum of Natural Numbers Using Recursion
Python compile()
Python hex()
Python Program to Catch Multiple Exceptions in One Line