What is the difference between a deep copy and a shallow copy in Python?

A shallow copy creates a new object but doesn’t create a copy of nested objects, instead it just copies the reference of nested objects.

A deep copy creates a new object and recursively adds the copies of nested objects present in the original elements. It means that any changes made to a copy of object do not reflect in the original object.

copy.copy() function is used for shallow copy and copy.deepcopy() function is used for deep copy.

Python Interview Questions

What is equivalent of “public static void main()” of Java in Python?

def main():
    # Code to execute

if __name__ == "__main__":
    main()