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

 

0 comments:

Post a Comment