프로그래밍 언어/파이썬

[Python] 리스트 복사

컴공맨 2021. 3. 28. 01:07
# 1
list = [1, 2, 3, 4]
copy_list = list[:]
copy_list[0] = 5
 
print(list)
print(copy_list)

# 출력결과
# [1, 2, 3, 4]
# [5, 2, 3, 4]

# 2
copy_list = list
copy_list[0] = 5

print(list)
print(copy_list)

# 출력결과
# [5, 2, 3, 4]
# [5, 2, 3, 4]