How to Use ord() Function in PythonPython Basics


The ord() function returns the ASCII value corresponding to the character.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

print("ord('a'):  ", ord('a'))

print("ord('A'):  ", ord('A'))

print("ord('C'):  ", ord('C'))

print("ord('z'):  ", ord('z'))

Output:

ord('a'):   97
ord('A'):   65
ord('C'):   67
ord('z'):   122

Syntax

ord(c)

Parameters

Name Description
c Character

Return Value

It returns the ASCII value corresponding to the character.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us