What is the difference between list and list[:] in python?

When reading, list is a reference to the original list, and list[:] shallow-copies the list.

When assigning, list (re)binds the name and list[:] slice-assigns, replacing what was previously in the list.

Also, don’t use list as a name since it shadows the built-in.

Leave a Comment