The chr() function in Python accepts an integer which is a unicode code point and converts it into a string representing a character.
Python chr() function
The valid range for num is 0 to 1,114,111
Returns a string representing a character whose unicode code point value is num.
Python chr() function Example
In the following example we are passing integers values in the chr() function that represents the unicode code point values and the function returns the corresponding characters (strings).
This function returns a string with length 1 which represents the character whose unicode code point value is passed in chr() function.
myString = chr(101) print(myString) myString2 = chr(47) print(myString2) myString3 = chr(1002) print(myString3)
Python chr() function ValueError Example
As I have already mentioned that the valid range for the integers that can be passed in the chr() function is 0 to 1,114,111, if we pass the value out of this range then we get the ValueError.
# ValueError example myString = chr(-10) print(myString)
S k jha says
In chr function if I input 111411 which is within the range, in that case why it gives error