+ 3
But why if I run the code I put into the description the output is True (the question is related to the previous one)
a = 12 b = 12 print(a is b)
2 Réponses
+ 4
Variable names are like labels. a = 12 means: create an integer object int(12) and use the label "a" to address it. So it's fundamentally different from other languages which use declarations like int a = 5, which means: make room for one integer, store the value 5 in it and call the whole thing "a". In python, a and b will point to the same integer object, so a "is" b.
/Btw, this works for strings too:
s = 'yay'
t = 'yay'
print(s is t) # True
+ 1
Anna thank you very much :)