首页 > 软件操作教程 > 编程开发 > Python
题目内容

python Copy 和 deepcopy

题目答案

>>> 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条评论)

请自觉遵守互联网相关政策法规,评论内容只代表网友观点!

最新评论

点击加载更多评论>>

软件操作 新人注册送三重礼

已有 22658 名学员学习以下课程通过考试

相关视频试题

最需教育客户端 软件问题一手掌握

去 App Store 免费下载 iOS 客户端