Python출력 결과보통 · 20점#리스트#얕은 복사#참조

97. 중첩 리스트의 대입·얕은 복사·깊은 복사 비교

다음 Python 프로그램의 실행 결과를 쓰시오.

1import copy
2
3base = [[1, 2], [3, 4], 5]
4alias = base
5shallow = base.copy()
6sliced = base[:]
7deep = copy.deepcopy(base)
8alias[2] = 50
9shallow[0][0] = 10
10shallow[2] = 99
11sliced[1] = [7, 7]
12sliced[0].append(0)
13deep[1][1] = 40
14print(base)
15print(shallow)
16print(sliced)
17print(deep)
18print(base[1] is shallow[1], base[1] is deep[1], base is alias)

해설을 먼저 보면 이후 정답 시 점수가 50%만 반영됩니다.