The chr() method returns a string representing a character whose Unicode code point is an integer.
chr(num) num : integer value
- The chr() method takes only one integer as argument.
- The range may vary from 0 to 1,1141,111(0x10FFFF in base 16).
- The chr() method returns a character whose unicode point is num, an integer.
- If an integer is passed that is outside the range then the method returns a ValueError.
Example: Suppose we want to print ‘G e e k s f o r G e e k s’.
G e e k s f o r G e e k s
Another example :
Character of ASCII value 17 is Character of ASCII value 38 is & Character of ASCII value 79 is O
What happens if we give something out of range?
We wont get any output and the compiler will throw an error:
Traceback (most recent call last): File "/home/484c76fb455a624cc137946a244a9aa5.py", line 1, in print(chr(400)) UnicodeEncodeError: 'ascii' codec can't encode character '\u0190' in position 0: ordinal not in range(128)
- Important differences between Python 2.x and Python 3.x with examples
- Python | Merge Python key values to list
- Python | Index of Non-Zero elements in Python list
- Python | Convert list to Python array
- Reading Python File-Like Objects from C | Python
- Python | Sort Python Dictionaries by Key or Value
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to Python Libraries
- Python | Add Logging to a Python Script
- Python | Visualizing O(n) using Python
- Use of min() and max() in Python
- Python vs PHP
- try and except in Python
- Any & All in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.