How to make shallow copying (not copy only creating a new reference) in Python

1 Answer

0 votes
arr = [1, 2, 3, 4]
b = arr
print("arr = ", arr, " b = ", b)

arr.append(5)
print("arr = ", arr, " b = ", b)


'''
run:

arr =  [1, 2, 3, 4]  b =  [1, 2, 3, 4]
arr =  [1, 2, 3, 4, 5]  b =  [1, 2, 3, 4, 5]

'''

 



answered Nov 30, 2017 by avibootz

Related questions

...