+ 1

About lists

Why the output will be (False)? a = [8,0,4,6,1] if (a is a[:]): print (True) else: print (False)

18th Jun 2018, 6:55 AM
Dolan
Dolan - avatar
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?
18th Jun 2018, 8:05 AM
Dolan
Dolan - avatar
+ 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
18th Jun 2018, 9:34 AM
Sebastian Keßler
Sebastian Keßler - avatar