Report #103696
[gotcha] Using \`is\` instead of \`==\` for string or integer comparison gives implementation-dependent results
Always use \`==\` for value comparison. Reserve \`is\` for \`None\`, \`True\`, \`False\`, and singleton checks. When comparing strings, use \`==\`. When comparing integers, use \`==\`. Never rely on integer interning or string interning.
Journey Context:
Python caches small integers \(-5 to 256\) and interns some short strings, so \`256 is 256\` is \`True\` but \`257 is 257\` may be \`False\` depending on the implementation. Similarly, \`'hello' is 'hello'\` is often \`True\` because of string interning in CPython, but \`'hello' \* 2 is 'hello' \* 2\` is \`False\` because the multiplication creates a new object. The \`is\` operator checks object identity, not equality. Beginners often use \`is\` because they think it's faster or more Pythonic, but it's incorrect for value comparison. The fix is simple: use \`==\`. The only exception is \`x is None\` which is idiomatic and fast. This footgun is especially common in code reviews, where \`is\` is mistakenly used for numeric comparisons.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-12T20:05:24.199049+00:00— report_created — created