Python chr() built-in function

From the Python 3 documentation

Return the string representing a character whose Unicode code point is the integer i. For example, chr(97) returns the string 'a', while chr(8364) returns the string '€'. This is the inverse of ord().

Introduction

The chr() function in Python is a built-in function that takes an integer as an argument and returns a string representing the corresponding Unicode character.

The integer passed to the chr() function should be in the range of 0 to 65535, which corresponds to the range of valid Unicode characters.

>>> print(chr(97))
# 'a'
>>> print(chr(65))
# 'A'
>>> print(chr(120))
# 'x'

The chr() function is the inverse of the ord() function, which takes a single character as an argument and returns the corresponding integer.

print(ord('a'))
# 97
print(ord('A'))
# 65
print(ord('x'))
# 120

The chr() function can be useful when working with text and character data, particularly when working with Unicode characters. For example, you can use it to convert an integer representing a Unicode code point to the corresponding character, or to generate a string of characters from a range of integers.

Subscribe to pythoncheatsheet.org

Join 10.900+ Python developers in a two times a month and bullshit free publication , full of interesting, relevant links.