The chr () function in Python
In Python, the chr () function returns a character (a string) from an integer that represents the unicode of the returned character.
In Python, the chr () function returns a character (a string) from an integer that represents the unicode of the returned character. So what is the syntax of chr () function, parameter and how to use chr ()? Let's find out together.
The chr () function syntax in Python
chr (i)
Parameters of chr ()
- Function chr () comes with a single parameter or an integer i
- Valid range of integers is from 0 to 1,114,111.
Return value from chr ()
The function chr () returns the value:
- A character (a string) with Unicode code is (i).
- If (i) is outside the valid range, the program will notify ValueError
For example:
print (chr (97))
print (chr (65))
print (chr (1200))
Running the above code, the program will return the result:
a
A
Ұ
Try an example with (i) outside the program's allowable scope:
print (chr (-1))
Immediately we have the result ValueError:
Traceback (most recent call last):
File "", line 1, print
print (chr (-1))
ValueError: chr () arg not in range (0x110000)
See more:
- Functions in Python
- Built-in Python functions
- More than 100 Python exercises have solutions (sample code)
Last lesson: callable () function in Python
Next lesson: classmethod () function in Python
Update 25 May 2019
You should read it
- The ord () function in Python
- The function id () in Python
- Int () function in Python
- The map () function in Python
- The oct () function in Python
- The function set () in Python
- The function dir () in Python
- Max () function in Python
- Exec () function in Python
- The next () function in Python
- Zip () function in Python
- Hex () function in Python
Maybe you are interested
What does the 'super slow' 7680fps movie recording feature on the Mate 30 Pro do? Hitman Sniper famous game is being free on iOS and Android How to create slow motion videos on Android? 8 ways to win people's hearts 6 tips to help you get out of debt Changing these 10 ways of speaking will help you advance like 'windy kites'.