import copy
a=[1,2,3,[4,5,6]]
c_a=copy.copy(a)
d_a=copy.deep(a)
c_a==d_a #True
a[3][0]='hello'
a #[1,2,3['hello',5,6]]
c_a #[1, 2, 3, ['hello', 5, 6]]
d_a #[1, 2, 3, [4, 5, 6]]
import copy
a=[1,2,3,[4,5,6]]
c_a=copy.copy(a)
d_a=copy.deep(a)
c_a==d_a #True
a[3][0]='hello'
a #[1,2,3['hello',5,6]]
c_a #[1, 2, 3, ['hello', 5, 6]]
d_a #[1, 2, 3, [4, 5, 6]]
本文标题:copy.copy和deep.copy
本文链接:https://www.haomeiwen.com/subject/fqaqbxtx.html
网友评论