Jan-28-2020, 03:09 AM
Hi all,
I've been trying to create a sequence in which a new value is based on the older value.
then the values change making the new value the old one and create a new value and so on in a for loop.
the problem I'm facing is when assigning a variable to a variable. If a change happens to one variable the other one changes to match the first one
here is a simple and easy example:
pt1 = [1,1,1]
pt2 = pt1
pt1[2] = pt1[2] * 2
print(pt1)
print(pt2)
the result that shows up is as follows:
[1, 1, 2]
[1, 1, 2]
isn't it supposed to be?
[1, 1, 2]
[1, 1, 1]
why did pt2 change after modifying pt1?
is there a way to assign the values of the variable instead of its path?
Thanks to anyone
I've been trying to create a sequence in which a new value is based on the older value.
then the values change making the new value the old one and create a new value and so on in a for loop.
the problem I'm facing is when assigning a variable to a variable. If a change happens to one variable the other one changes to match the first one
here is a simple and easy example:
pt1 = [1,1,1]
pt2 = pt1
pt1[2] = pt1[2] * 2
print(pt1)
print(pt2)
the result that shows up is as follows:
[1, 1, 2]
[1, 1, 2]
isn't it supposed to be?
[1, 1, 2]
[1, 1, 1]
why did pt2 change after modifying pt1?
is there a way to assign the values of the variable instead of its path?
Thanks to anyone