To copy an existing list to another in Python, we can use copy () function and the function is invoked on the existing list object. This function returns a new object in which the elements of the existing list is copied.
Copy a List
mylist = ["assam", "banaras", "chennai"]
clist = mylist.copy()
Another way to make a copy is to use the built-in method list().
Example
mylist = ["assam", "banaras", "chennai"]
clist = list(mylist)
No comments:
Post a Comment