copy - Python

« Previous Topics
Shelve
Copy_reg
Cpickle
Next Topics »
Marshal
Imp
Parser

The copy module provides shallow and deep object copying operations for lists, tuples, dictionaries, and class instances.

copy.copy()

This function creates a shallow copy of the x object.

As you can see at the end of the previous example, the new list is not the old one.

As you can see, this function provides the same result that y=x[:] does. It creates a new object that references the old one. If the original object is a mutable object and has its value changed, the new object will change too.

copy.deepcopy()
It recursively copies the entire object. It really creates a new object without any link to the original structure.

basic syntax:
« Previous Topics
Shelve
Copy_reg
Cpickle
Next Topics »
Marshal
Imp
Parser

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Python Topics