0
what is the meaning of b=a when a is a list?see my example please.
a=[1,2,3]b=a after a.append[4] or other operater. a,b is always the same.
4 ответов
+ 2
a=[1,2,3];
b=a;
a.push(4)
alert(a)
alert(b)
js also
Ans : This is Reference
+ 2
Yes as he pointed/elaborate out
You have to do like this
a=[1,2,3]
b=a[:] #slice with empty will return copy form
a.append(4)
0
Look up the difference between reference types and value types. Reference types only store the reference of the object, such as a list, so the value of the variable is just a link to the actual object. Multiple variables just means multiple links to the same object. You need to do a deep copy to make a new list if you want to keep the original one separate.
0
thanks for your help.~( ̄▽ ̄~)~The fact is that if i can use a[list] to do what i want ,why i use b instead?i will look up the usage of reference type.some example is also very helpful.Love you guys