Python Glossary Русский

all Python 3Built-in functionsterm

chr

strings

Returns a one-character string for the given Unicode code point (an integer). The inverse of ord().

Syntax

chr(i)

The argument is a Unicode code point, not a byte: chr(200) gives 'È', while a byte with value 200 comes from bytes([200]). Valid values are 0 through 0x10FFFF and anything else raises ValueError; surrogate codes 0xD800-0xDFFF are accepted but the resulting string cannot be encoded to UTF-8 afterwards.

Examples

print(chr(65))   # → A
print(chr(97))   # → a
print(chr(1072)) # → а (кириллица)
print(chr(9829)) # → ♥
print(''.join(chr(i) for i in range(65,70)))  # → ABCDE

See also

Open in the full glossarydocs.python.orgReport an inaccuracy