
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert Integer to ASCII Value in Python
Converting Integer to ASCII Using chr() Function
In Python, the chr() function converts an integer value to the corresponding ASCII (American Standard Code for Information Interchange) character only if the integer range lies between 0 and 127.
The chr() function accepts Unicode values within the range of 0 to 1114111. If a value outside this range is provided, the function raises a ValueError.
Example
In the following example, we have converted integer values to ASCII values using chr() -
print(chr(85)) print(chr(100)) print(chr(97))
Following is the output of the above code -
U 100 a
Example
We can use the chr() function to print all the alphabets by iterating through their ASCII values.
for i in range(65,91): print(chr(i),end=" ")
Output
Following is the output of the above code ?
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Converting Integer to ASCII Using ord() Function
The ord() function is another built-in function that converts ASCII characters to their corresponding integer value.
Example
In the following example, we have converted ASCII characters to integers using ord() function -
print(ord('A')) print(ord('S')) print(ord('I'))
Following is the output of the above code ?
65 83 73