prize18-1 Exercise 2: Three Ways to Count a String ==================================================== Predictions: "cafe" = 4 code points / 4 bytes. "caf" + U+00E9 = 4 code points / 5 bytes (the accented letter takes 2 bytes). "cafe" + U+0301 (combining acute) = 5 code points / 6 bytes, yet it looks the same as the previous one. Two regional indicator letters (J, P) = 2 code points / 8 bytes (4 each), but a reader sees one flag. ex2.py: def describe(s): print(f"{s!r}: code points={len(s)}, utf-8 bytes={len(s.encode('utf-8'))}") print(" ", " ".join(f"U+{ord(c):04X}" for c in s)) for text in ["cafe", "caf\u00e9", "cafe\u0301", "\U0001F1EF\U0001F1F5"]: describe(text) Real output (Python 3.14): 'cafe': code points=4, utf-8 bytes=4 U+0063 U+0061 U+0066 U+0065 'café': code points=4, utf-8 bytes=5 U+0063 U+0061 U+0066 U+00E9 'café': code points=5, utf-8 bytes=6 U+0063 U+0061 U+0066 U+0065 U+0301 '🇯🇵': code points=2, utf-8 bytes=8 U+1F1EF U+1F1F5 Takeaway: len() in Python counts code points, not bytes and not what a reader sees. The two "café" strings look identical but have different lengths.