For example, like this. Numerical values and character strings produce the expected results.
####Numerical value####
num = 1
ber = num
num += 1
print(num) # 2
print(ber) # 1
####String####
te = "a"
xt = te
te += "b"
print(te) # ab
print(xt) # a
But with an array,
####Array####
li = [1,2]
st = li
li.append(3)
st.append(4)
print(li) # [1,2,3,4]
print(st) # [1,2,3,4]
** If you update one, the other is also updated, so you can see that they are the same object. ** **
So what the above st = li
means is that the object named
li can now also be referenced by the name` `st
. It's just that (I don't know if you need to do that).
Recommended Posts