Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Created December 5, 2019 01:25
Show Gist options
  • Save FerdinaKusumah/8cac72d37dafb6a8ee8e77b38a2e6406 to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/8cac72d37dafb6a8ee8e77b38a2e6406 to your computer and use it in GitHub Desktop.
Copy or Clone Variable
from copy import deepcopy
"""Clone or copy object to new ones"""
a = [1, 2, 3, 4]
b = deepcopy(a)
"""Try to adding new value in list a"""
a.append(5)
"""Now print this value"""
print("Value in a is {}".format(a))
# Value in a is [1, 2, 3, 4, 5]
print("Value in b is {}".format(b))
# Value in b is [1, 2, 3, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment