Python: "==" vs "is"
The newbies in Python confuse operators "==" and "is". And sometimes them even thinking that it's the same thing. But this is wrong. It's different.
The simple rule is:
- "==" evaluates True if the objects are different but they contain equal values;
- "is" evaluates True only if the objects are same.
>>> first = ['a', 'b', 'c', 'd'] >>> second = first >>> first == second True >>> first is second True
>>> third = ['a', 'b', 'c', 'd'] >>> first == third True >>> first is third False