Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the function of copy module in python

Shulou Source: shulou.com Published: 2022-06-03 17:37:38 09月21日 Update

This article mainly shows you "how to use the function of copy module in python", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn how to use the function of copy module in python "this article.

1. The copy.copy () function can be used to copy variable values such as lists or dictionaries. The copied list and the original list are two separate lists.

Import copyorigin = [1Jing 2 Jue 3] new = copy.copy (origin) new [0] = 0print ("origin =", origin) print ("new =", new)

2. If there is a list in the list you want to copy, use the deepcopy () function to copy it completely.

Import copyorigin = [1python 2jin3], new = copy.deepcopy (origin) # use deep copynew [0] [0] = 0print ("origin =", origin) print ("new =", new) all the contents of this article "how to use the functions of copy module in python", thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Functions modules content articles learning help two dictionaries easy to understand more organization knowledge editing industry information information channels channels variable independent research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn Shulou Information Linux Shulou Technology