The chr()
function returns a string representing a character from the given Unicode code integer. For example the integer 'a' has a unicode code of 97, therefore, chr(97)
returns the string 'a'.
Syntax:
chr(integer_code)
print(chr(97))
print all the characters with a unicode code from 70 and 80
for i in range(70, 80):
print(chr(i))
All the lowercase letters has Unicode values from 97,to 122, where 'a' has a code of 97 and 'z' has a code of 122, and the others are in between. We can print the lowercase letters using chr() as follows.
for i in range(97, 123):
print(chr(i), end = ' ')
The integer code value must be in the range 0-1114111 (0x10FFFF in base 16). If the argument is outside this range, a ValueError will be raised.
print(chr(1114112))
more examples:
for i in range(1000, 1020):
print(chr(i), end = ' ')
print( end = '\n')
print('----------------------------------------------')
for i in range(10000, 10020):
print(chr(i), end = ' ')
The ord() function serves exactly the opposite purpose, where you give it a character and it returns the unicode integer code of the character.