~/talk

Why `len('😶‍🌫️') == 4` and other weird things you should know about strings in Python

Talkat PyCon US 2025 · 2025-05-16..05-18· [python, web-platform]
links:none on file
links:none on file
slides:none on file

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

  1. 0:00Introduction to python strings
  2. 2:16Understanding string encoding
  3. 7:50Comparing strings correctly
  4. 11:17Unicode normalization
  5. 15:03Edge cases in unicode
  6. 17:07Slicing and grapheme clusters
  7. 22:15Summary and conclusion
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.