+ 2
I don't know why the ouput is "True". Help me please!
The output of this code is "True": a = '''text''' b = 'text' print(a is b). Can you explain to me? Thanks for reading.
2 RĂ©ponses
+ 7
PhĂșc ,
in this case python shares the data (in memory) "text" for both variables *a* and *b*.
we can check this with using the built-in function id():
...
print(id(a), id(b))
when we add this line to your code, the output for *a* and. *b* will be the same.
if we now modify one of the variables like:
...
b += "!"
print(id(a), id(b))
the id's of the variables are no longer the same
...
print(a is b)
will give *False* now
+ 1
Lothar Thank you so much