본문 바로가기
Programming/Python

copy - shallow, deep : 깊은복사, 얕은복사

by Chan_찬 2020. 8. 19.
728x90
반응형

python - deepcopy

list

>>> num_list = [1,2,3,4]

# deep copy
>>> new_list = num_list[:]
>>> new_list2 = list(num_list)

set

>>> str_set = {'Jane', 'Tim', 'John'}

# deep copy
>>> new_set = str_set.copy()

dict

>>> str_dict = {'hi': 'world'}

# deep copy
>>> new_dict = str_dict.copy()

use copy module

>>> import copy
>>> object = 'other something object'
>>> new_obj = copy.copy(object)  # shallow copy
>>> new_obj2 = copy.deepcopy(object)  # deep copy
728x90
728x90
BIG
Buy me a coffeeBuy me a coffee

댓글