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

How to avoid having class data shared among instances in python?

457


Write a program in python to check if a sequence is a palindrome.

485


How will you remove an object from a list?

447


What are tuples in python?

481


Is numpy faster than pandas?

439






What is for-else and while-else in python?

475


What does serialization mean in python?

433


What are negative indices?

468


Where is python used in real world?

452


What is class in python?

489


Does python have a switch-case statement?

471


Does facebook use python?

422


What is python software?

425


What does [::-1} do?

447


What are the differences between python 2.x and python 3.x?

524