일차배열, 이차배열
⭐️내용 보충 예정⭐️
얕은 복사 = swallow copy
동일한 주소값을 공유하기 때문에 서로 영향을 줌
깊은 복사 = deep copy
주소값을 공유하지 않기 때문에 서로 영향을 주지 않음
✔️ =
N = [3, 2, 5, 7, 1, 9]
swallowN = N
>> id(N) = 2165412876872
>> id(swallowN) = 2165412876872
>> id(N[0]) = 140736790688080
>> id(swallowN[0]) = 140736790688080
N[0] = 'a'
>> N = ['a', 2, 5, 7, 1, 9]
>> swallowN = ['a', 2, 5, 7, 1, 9]
>> id(N[0]) = 2165413244016
>> id(swallowN[0]) = 2165413244016
✔️ copy
N = [3, 2, 5, 7, 1, 9]
swallowN = N.copy()
>> id(N) = 3152113914440
>> id(swallowN) = 3152113914952
>> id(N[0]) = 140736790688080
>> id(swallowN[0]) = 140736790688080
N[0] = 'a'
>> N = ['a', 2, 5, 7, 1, 9]
>> swallowN = [3, 2, 5, 7, 1, 9]
>> id(N[0]) = 3152114281584
>> id(swallowN[0]) = 140736790688080
✔️ 슬라이싱[:]
N = [3, 2, 5, 7, 1, 9]
swallowN = N[:]
>> id(N) = 2408926892552
>> id(swallowN) = 2408926893064
>> id(N[0]) = 140736790688080
>> id(swallowN[0]) = 140736790688080
N[0] = 'a'
>> N = ['a', 2, 5, 7, 1, 9]
>> swallowN = [3, 2, 5, 7, 1, 9]
>> id(N[0]) = 2408931781744
>> id(swallowN[0]) = 140736790688080
✔️ deepcopy
import copy
N = [3, 2, 5, 7, 1, 9]
deepN = copy.deepcopy(N)
print("id(N) = ", id(N))
print("id(deepN) = ", id(deepN))
>> id(N) = 1814854491144
>> id(deepN) = 1814854491208
import copy
N = [3, 2, 5, 7, 1, 9]
deepN = copy.deepcopy(N)
print("id(N[0]) = ", id(N[0]))
print("id(deepN[0]) = ", id(deepN[0]))
>> id(N[0]) = 140736790688080
>> id(deepN[0]) = 140736790688080 # WHY? -> mutable immutable 별표 꽝
N[0] = 'a'
print("id(N[0]) = ", id(N[0]))
print("id(deepN[0]) = ", id(deepN[0]))
>> id(N[0]) = 2940193926256
>> id(deepN[0]) = 140736790688080
✔️ 이차배열 deepcopy
import copy
N = [[3, 2], [5, 7], [1, 9]]
N_deep = copy.deepcopy(N)
print("N = ", id(N))
print("N_deep = ", id(N_deep))
>> N = 1846881730056
>> N_deep = 1846882392392
print("N[0] = ", id(N[0]))
print("N_deep[0] = ", id(N_deep[0]))
>> N[0] = 1846881729928
>> N_deep[0] = 1846882392840