Python: chr() function
chr() function
The chr() function returns the string representing a character whose Unicode codepoint is the integer.
Note that on narrow Unicode builds, the result is a string of length two for i greater than 65,535 (0xFFFF in hexadecimal).
Syntax:
chr(i)
Version:
(Python 3.2.5)
Parameter:
Name | Description | Required/ Optional |
---|---|---|
i | A character whose Unicode codepoint is the integer i. he valid range for the argument is from 0 through 1,114,111 (0x10FFFF in base 16). ValueError will be raised if i is outside that range. | Required |
Return value:
Return the string representing a character whose Unicode codepoint is the integer i.
Example: Python chr() function
print(chr(65))
print(chr(97))
print(chr(124))
Output:
A a |
Example: Integer passed to chr() is out of the range
print(chr(-5))
Output:
Traceback (most recent call last): File "/tmp/sessions/0feab4034af997d8/main.py", line 1, in print(chr(-5)) ValueError: chr() arg not in range(0x110000)
Python Code Editor:
Previous: callable()
Next: classmethod()
Test your Python skills with w3resource's quiz
Python: Tips of the Day
How do I check if a list is empty?
For example, if passed the following:
a = [] if not a: print("List is empty")
Ref: https://bit.ly/2A4JXx9
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework