位置:首頁 > 軟件操作教程 > 編程開發(fā) > Python > 問題詳情

python Copy 和 deepcopy

提問人:楊紫紅發(fā)布時間: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


繼續(xù)查找其他問題的答案?

相關(guān)視頻回答
回復(fù)(0)
返回頂部