Text versus bytes
Learn in depth →str contains Unicode text; bytes contains integer byte values. Encoding and decoding cross that boundary.
text.encode("utf-8"); data.decode("utf-8")Example
text = "café"
data = text.encode("utf-8")
print(len(text), len(data), data.decode("utf-8"))Result
4 5 café
Watch for: The encoding must match the data. Ignoring decoding errors can silently lose information.
Practise this topic →