Possible Duplicate:
String comparison in Python: is vs. ==
When is the==operator not equivalent to theisoperator? (Python)
I’m pretty new to Python still. I heard someone say use is, not == because “this isn’t C”. But I had some code x is 5 and it was not working as expected.
So, following proper Python/PEP style, when is the time to use is and when is the time to use == ?
You should use
==to compare two values. You should useisto see if two names are bound to the same object.You should almost never use
x is 5because depending on the implementation small integers might be interned. This can lead to surprising results: