+ 4
Explain this code plz anyone
a = [8,6,9,4,6] If (a is a[:]): Print(True) else: Print(False) Why Is the results False(am just confused)
3 Respuestas
+ 3
If you want more details, you can read this mini tutorial:
https://code.sololearn.com/c89ejW97QsTN/?ref=app
+ 18
the expression *a is a[:]* returns False, since *a[:]* creates a (deep)copy of the list *a* with a different id / identity / reference (memory address).
*is* operator checks for identity.
checking for equality with *a == a[:]* returns True, since both lists have equal elements.
+ 7
id(a) is not equal to id(a[:])