Table of Contents
The chr() method returns a character (a string) from an integer (represents unicode code point of the character).
The syntax of chr() is:
chr(i)
1. chr() Parameters
chr() method takes a single parameter, an integer i.
The valid range of the integer is from 0 through 1,114,111.
2. Return Value from chr()
chr() returns:
- a character (a string) whose Unicode code point is the integer i
If the integer i is outside the range, ValueError will be raised.
3. Example 1: How chr() works?
print(chr(97)) print(chr(65)) print(chr(1200))
Output
a A Ұ
Here, 97 is the unicode of a, 65 is the unicode of A, and 1200 is the unicode of Ұ.
4. Example 2: Integer passed to chr() is out of the range
print(chr(-1))
Output
Traceback (most recent call last): File "", line 1, in ValueError: chr() arg not in range(0x110000)
When you run the program, ValueError is raised.
It’s because the argument passed to chr() method is out of the range.
The reverse operation of chr() function can be performed by ord() function. To learn more, visit Python ord() function
Related posts:
Python Input, Output and Import
Python String swapcase()
Python Get Current time
Python break and continue
Python Program to Find Factorial of Number Using Recursion
Python List clear()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Directory and Files Management
Python List copy()
Python Tuple index()
Python int()
Python Program to Print Colored Text to the Terminal
Python Program to Find the Largest Among Three Numbers
Python Program to Slice Lists
Python Decorators
Python Exception Handling Using try, except and finally statement
Python sorted()
Python Program to Sort Words in Alphabetic Order
Python Program to Return Multiple Values From a Function
Python complex()
Intelligent Projects Using Python - Santanu Pattanayak
Python hex()
Python Modules
Python dir()
Python Program to Create a Long Multiline String
Python property()
Python next()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python strftime()
Python Set symmetric_difference_update()
Python bool()
Python Program to Convert Kilometers to Miles