import copy
name_list = ["kill", "ait", ["jack", "wang", "woh"], "hell"]
# Shallow copy
name1 = name_list.copy()
""" The following three also belong to Shallow copy name1 = copy.copy(name_list) name1 = name_list[:] name1 = list(name_list) """
print(name1)
name_list[1] = "wangjjj"
name_list.append("worllld")
print(name_list)
print(name1)
name_list[2][1] = " Excellent "
name_list[2].append(" Su Qin ")
print(name_list)
print(name1)
print(" Split line ----------------")
# Deep copy ( Careful use , When the amount of data is large , Deep copy takes up a lot of memory )
name_list2 = ["alex", "ait", ["jack", "wang", "woh"], "hell"]
name2 = copy.deepcopy(name_list2)
print(name2)
name_list2[1] = "wangjjj"
name_list2.append("worllld")
print(name_list2)
print(name2)
name_list2[2][1] = " Excellent "
name_list2[2].append(" Su Qin ")
print(name_list2)
print(name2)
print(" Split line -------------")
# Simple application of shallow copy : Husband and wife share an account , Different names , But deposits are the same
person = ['name', ['saving', 100]]
husband = person[:]
wife = person[:]
husband[0] = ' I am my husband '
wife[0] = ' I am a wife '
print(husband)
print(wife)
# My husband spent 30 block , be left over 70 block , My wife's account also changes with me
husband[1][1] = 70
print(husband)
print(wife)