Web Development and Design | Tutorial for Java, PHP, HTML, Javascript: python-copy-list-by-value

Web Development and Design | Tutorial for Java, PHP, HTML, Javascript: python-copy-list-by-value
Showing posts with label python-copy-list-by-value. Show all posts
Showing posts with label python-copy-list-by-value. Show all posts

Python Copying a list

Python Copying a list




Copying a list

To copy a list make a slice that starts at the first item and ends at the last item. If you try to copy a list without using this approach, whatever you do to the copied list will affect the original list as well.

#Making a copy of a list
finishers =['kai', 'abe', 'ada', 'gus', 'zoe']
copy_of_finishers = finishers[:]
print(copy_of_finishers)

Screenshot

python copy list