+ Deep copy and shallow copy variable data types and immutable

Deep copy and shallow copy

import copy


= L [1,2,3,4, [ 'A', 'B', 'C']]
L2 = copy.deepcopy (L) # This is the only deep copy is
l2 = l [:] # shallow copy
l2 = l # shallow copy
l2 = l.copy () # shallow copy

 

The variable data types and immutable

 

Variable data types: list, dict

Non-variable data type: tuple, str, float, int

Guess you like

Origin www.cnblogs.com/wangyujian/p/11514361.html