Last modified: Jan 10, 2023 By Alexander Williams
make a copy of an object in python
in these examples we'll learn how to copy an object in python by using two methods
Table Of Contents
method 1: regular method
#string
old_string = "hello world"
#new string
new_string = old_string
print(new_string)
output
hello world
method 2 : copy using Copy Module
syntax
copy.copy(string)
#module
import copy
#old string
old_string = "hello world"
#new string
new_string = copy.copy(old_string)
print(new_string)
output
hello world