is
the result will be true only if the object is the same object.
==
will be true if the values โโof the object are the same.
>>> S1 = 'HelloWorld'
>>> print id(S1)
4457604464
>>> S2 = 'HelloWorld'
>>> print id(S2)
4457604464
>>> S1 is S2
True
The above code means S1
and S2
- the same object. And they have the same memory location. So there S1
is S2
.
>>> S1 = 'Hello World'
>>> S2 = 'Hello World'
>>> print id(S1)
4457604320
>>> print id(S2)
4457604272
>>> S1 is S2
False
Now they are different objects, therefore S1
not S2
.
source
share