Python Glossary Русский

all Python 3unicodedatafunction

unicodedata.decomposition()

normalization

Returns a character's decomposition as a string of hex code points, for example '0438 0306' for 'й', or an empty string if there is none.

Syntax

unicodedata.decomposition(chr, /)

The result is text, not characters: to get a string you parse the codes with int(x, 16) and chr(). A tag in angle brackets ('<compat>', '<super>') marks a compatibility decomposition that only NFKC/NFKD apply, and it changes meaning ('²' becomes '2'). For actual normalization use normalize(); decomposition() shows a single, non-recursive step.

Examples

import unicodedata
print(unicodedata.decomposition('й'))  # → 0438 0306
print(unicodedata.decomposition('²'), repr(unicodedata.decomposition('a')))  # → <super> 0032 ''
print(''.join(chr(int(x, 16)) for x in unicodedata.decomposition('й').split()) == 'и\u0306')  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy