I normally understand how slices behave to the left and right of the assignment operator.
However, I've seen this in the Python (3.8.0) manual and trying to figure out what I'm missing.
clear the list by replacing all the elements with an empty list
letters[:] = []
How's that different from just letters = []?
(It's not easy to search for [:] as stackoverflow thinks you're looking for a tag. So, if there is already an answer I couldn't locate it.)
I see some rather irrelevant answers. So, to hopefully clarity, the question is not about what the [:] slice means, rather about assigning the empty list to one.
letterspoints to. If you just useletters =then the other variable won't be affected, but if you useletters[:] =then the value visible via the other variable is modified!lettersis a function parameter. Thenletters[:] = []will change the argument passed to the function butletters = []won't.