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:
Intelligent Projects Using Python - Santanu Pattanayak
Python Tuple count()
Python String isdecimal()
Python Program to Check if a Number is Odd or Even
Python Set pop()
Python Operators
Python Program to Concatenate Two Lists
Python Program to Illustrate Different Set Operations
Python Set isdisjoint()
Python Program to Find the Factorial of a Number
Python List copy()
Python isinstance()
Python Program to Check the File Size
Python Generators
Python hasattr()
Python Shallow Copy and Deep Copy
Python RegEx
Python Program to Make a Flattened List from Nested List
Python Program to Access Index of a List Using for Loop
Python Set intersection()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python list()
Python Dictionary clear()
Python Program to Parse a String to a Float or Int
Python Machine Learning Eqution Reference - Sebastian Raschka
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python String rpartition()
Python Object Oriented Programming
Python round()
Python complex()
Python String rindex()
Python Program to Iterate Over Dictionaries Using for Loop