位置:首页 > 软件操作教程 > 编程开发 > Python > 问题详情

python Copy 和 deepcopy

提问人:杨紫红发布时间:2020-11-18

>>> harry = Animal('hippogriff', 6, 'pink')

>>> carrie = Animal('chimera', 4, 'green polka dots')

>>> billy = Animal('bogill', 0, 'paisley')

>>> my_animals = [harry, carrie, billy]

>>> more_animals = copy.copy(my_animals)

>>> print(more_animals[0].species)

hippogriff

>>> print(more_animals[1].species)

Chimera

>>> my_animals[0].species = 'ghoul'

>>> print(my_animals[0].species)

ghoul

>>> print(more_animals[0].species)

ghoul


>>> more_animals = copy.deepcopy(my_animals)

>>> my_animals[0].species = 'wyrm'

>>> print(my_animals[0].species)

Wyrm

>>> print(more_animals[0].species)

ghoul


继续查找其他问题的答案?

相关视频回答
回复(0)
返回顶部