+ 1
About lists
Why the output will be (False)? a = [8,0,4,6,1] if (a is a[:]): print (True) else: print (False)
2 ответов
+ 2
Jan Markus Can we say that we specified another variable (again named (a)) so it is different from the first variable (a)!?
if yes, then how can (a==a[:]) will be True?
are they count as different variables with same arguments?
+ 2
Jay Matthews is right. To see if both variables hold the same Content use '=='. To see if both variables are related to the same Object use 'is'
b = a
print (a == b) #true
print (a is b) #true
b = a[:]
print (a == b) #true
print (a is b) #false