Explain how to copy an object in Python.

Answer Posted / chaitanya

There are two ways in which objects can be copied in python.

Shallow copy & Deep copy.

Shallow copies duplicate as minute as possible whereas Deep copies duplicate everything.

If a is object to be copied then

-copy.copy(a) returns a shallow copy of a.

-copy.deepcopy(a) returns a deep copy of a.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Use of double quotes and single quote in python?

505


What is design pattern in python?

436


Is python good for microservices?

413


How do you convert string as a variable name in python?

471


What are closures in python?

500






What is the difference between old style and new style classes in python?

465


How do I apply a method to a sequence of objects?

538


In python, how do copy a file?

396


What is the meaning of @classmethod and @staticmethod ?

464


When does a dictionary is used instead of a list?

445


What is namespace in Python?

504


What is a counter in python?

554


Can I use Python instead of PHP?

496


Explain what is a flask? What are its benefits?

459


What python frameworks do you know?

427