Python: shallow copy vs deep copy

Self-tutoring about Python: shallow copy vs deep copy.

A deep copy is a new object: if you change its source, the deep copy won’t change. However, if you change the source, a shallow copy will change with it, if the change is made to a mutable object. Therefore, reassigning a string won’t alter its shallow copy: Python strings are immutable.

docs.python.org

docs.python.org

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply