KITFORMA · EDITORIAL GUIDE
How do I distinguish a missing dictionary key from a stored None value?
KitForma editorial guide. `mapping.get(key)` returns `None` both for a missing key and for an explicitly stored `None`. That loses information when null is meaningful.
Step-by-step guidance
mapping.get(key) returns None both for a missing key and for an explicitly stored None. That loses information when null is meaningful.
Use membership testing, or create missing = object() and call mapping.get(key, missing). Compare the result with is missing, not equality. Test three cases independently: missing, present with None, and present with an empty string. Do not use truthiness to decide presence when zero, false and empty containers are valid values. Keep a sentinel private to the operation; serializing it or accepting it as public input would complicate the contract.Sources and verification
Sources checked:
Scope: This editorial guide is based on the cited sources and tool behavior. A forum question or a query observed for our site does not establish market search volume, low competition, guaranteed rankings or inadequate answers elsewhere.
This starter guide was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.