Why `len('😶🌫️') == 4` and other weird things you should know about strings in Python
summary
len('😶🌫️') == 4 is explained: emoji form from multiple code points (flag + variant selector-16 + zero-width joiner + rainbow), Python sometimes stores strings as 1/2/4-byte internally, and grapheme clusters can be many code points. Practical specifics: use casefold for caseless matching, normalize with NFC/NFD or NFKC/NFKD for equivalence, avoid comparing with is (string interning causes accidental matches), and handle visual characters with a Unicode-aware library like regex, PyICU rather than byte-level slicing.
AI-written summary · about
chapters (7)
- 0:00Introduction to python strings
- 2:16Understanding string encoding
- 7:50Comparing strings correctly
- 11:17Unicode normalization
- 15:03Edge cases in unicode
- 17:07Slicing and grapheme clusters
- 22:15Summary and conclusion
related talks
25mWhy len 4 and other weird things you should know about strings in Python
51mCharBusters - 10 Unicode Myths
44mA 🐍's guide to Unicode
35mText Is Not Text: The History of Strings in Python
21mEmoji Encoding, Unicode, and Internationalization
34mEmoji Encoding, � Unicode, & Internationalization
28mEmoji Encoding
31mHow a Single ß Can Break Everything
