CKTIS / Python
Unicode text and bytes
A str is an immutable sequence of Unicode code points, while bytes hold encoded octets.
Version: Python 3.14; repository image, production runtime not attested
Syntax
unicodedata.normalize("NFC", text)A str is an immutable sequence of Unicode code points, while bytes hold encoded octets.
Visually similar text may have different code-point sequences, lengths and equality results. NFC normalization can bring canonically equivalent forms to a common representation.
UTF-8 byte length can still differ from the number of code points.
Examples
from unicodedata import normalize
composed = "é"
split = "e\u0301"
print(composed == split, len(composed), len(split))
print(normalize("NFC", split) == composed, len(composed.encode("utf-8")))
print("Straße".casefold() == "STRASSE".casefold())
Result
False 1 2 True 2 True
UTF-8 byte length can still differ from the number of code points.