~/talk

Why len 4 and other weird things you should know about strings in Python

Talkat PyCon UK 2025 · on Sunday, 2025-09-21· at 14:00· Main stage· [python, web-platform]
links:none on file
slides:none on file

Python reports surprising counts and mismatches because of encoding, normalization and grapheme clusters: len('😶‍🌫️') == 4 and 'ñ' != 'ñ' happen because code points, variant selectors and zero‑width joiners combine into visible characters. Python uses 1/2/4‑byte internal storage and applies string interning so identity can lie (avoid is, use ==). Use Unicode normalization (NFC/NFD, NFKC/NFKD) and casefold for caseless matches (handles ~297 odd mappings). No built‑in grapheme support — handle visual characters with regex or PyICU.

AI-written summary · about

  1. 0:00Unicode strings in Python
  2. 1:25String encoding basics
  3. 3:12Unicode and UTF-8
  4. 5:39Code points and categories
  5. 6:23Danger of 'is' for strings
  6. 7:49Caseless comparison pitfalls
  7. 9:12Case folding for matching
  8. 10:02Normalization issues
  9. 12:31Identifier normalization
  10. 13:16Homoglyphs and confusables
  11. 14:44Language-specific casing
  12. 15:05Slicing strings tricky
  13. 16:51Emojis and grapheme clusters
  14. 18:39Unicode checklist
  15. 21:07Q&A
~/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.