+ 3

Can somebody tell me why the output of this code is False ❓

https://code.sololearn.com/cmT2EvyiaEL4/?ref=app

9th Feb 2020, 5:17 PM
ClassHacker
ClassHacker - avatar
4 Respuestas
+ 10
The is operator compares the identity of two objects. x is y only when x and y refer to the same object. x = [0,0,0] y = x print(x is y) Use the id() function to check the identity of objects. If id(x) and id(y) are the same, then (x is y) is true. https://docs.python.org/2/library/functions.html#id Also compare '==' vs 'is'. https://www.sololearn.com/Discuss/1122173/
9th Feb 2020, 5:27 PM
Hatsy Rei
Hatsy Rei - avatar
+ 4
What do you mean by saying " Why y[0][0] = 1 is different from z[0][0] = 1"? Can you give a bit more details?
9th Feb 2020, 7:45 PM
Lothar
Lothar - avatar
+ 1
Even if the code was like this y=[[0,0,0],[0,0,0],[0,0,0]] z=[[0,0,0],[0,0,0],[0,0,0]] print(y is z) it will still print false, this is not the correct usage for "is" Use ==
9th Feb 2020, 9:13 PM
Karim Salah
Karim Salah - avatar
0
Why y[0][0] =1 is different from z[0][0] =1 ❓
9th Feb 2020, 5:56 PM
ClassHacker
ClassHacker - avatar