I tried these codes on a list slice a[:]
when I was learning list methods:
a = list('zyx')
a[:].pop()
print(a)
a = list('zyx')
a[:].append('o')
print(a)
a = list('zyx')
a[:].clear()
print(a)
a = list('zyx')
a[:] = []
print(a)
and the results I got are:
['z', 'y', 'x']
['z', 'y', 'x']
['z', 'y', 'x']
[]
What makes me confused is both the list methods and the reassignment changed the list slice, but why did the reassignment affect the original list while the list methods did not?
I know it might be about shallow copy, but I can not tell exactly why.