Compare two rows of a group, return different results

I run this

+3
source share
1 answer

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 S1and S2- the same object. And they have the same memory location. So there S1is 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 S1not S2.

0
source

Source: https://habr.com/ru/post/1015140/


All Articles