+ 3
Can somebody tell me why the output of this code is False ❓
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/
+ 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?
+ 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 ==
0
Why y[0][0] =1 is different from z[0][0] =1 ❓