Is it better to use “is” or “==” for number comparison in Python? [duplicate]

Use ==.

Sometimes, on some python implementations, by coincidence, integers from -5 to 256 will work with is (in CPython implementations for instance). But don’t rely on this or use it in real programs.

Leave a Comment