+ 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)

6th Apr 2019, 12:11 PM
mihai
mihai - avatar
2 Antworten
+ 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
6th Apr 2019, 12:30 PM
Anna
Anna - avatar
+ 1
Anna thank you very much :)
6th Apr 2019, 12:43 PM
mihai
mihai - avatar