0
What is the output and why?
a=[1,2,3,4] b=a a[2]=5 print(b)
3 Respostas
+ 1
That's because in Python the assignment points to same object.
So b is just another name for the object, which was called a.
If you want b to be another object, you need to modify the line b=a to
b = a.copy()
Then if you change an element in a, it's not affecting b
0
The output is [1,2,5,4]
a=[1,2,3,4] //here a[2]=3
b=a
a[2]=5 //Here replacing the value a[2]=3 to a[2]=5
print(b)//so the output is [1,2,5,4]
0
but we are printing b not a?