For example,
a = [1,2,3]
b = a
a.remove(1)
print(b)
When you do, [2, 3] is output. If you take the id(), the address is the same. I mean, the assignment operator '=' seems to hand over the address of the object. Is there a way to hand over only the value of a ([1,2,3]) by changing the address of b?
Simply put, we want the output of the above code to be [1,2,3]. Thank you.
python
You can use one of the following instead of b = a.
b = a.copy()
b = a[:]
b = list(a)
© 2024 OneMinuteCode. All rights reserved.