0
loop
Please explain to me, how the output of this: A=[1,2,3,4,1] for n in A: A[n]=0 print(A) is [0,0,3,0,1] ?
4 Answers
+ 7
In first iteration,
A[1] becomes 0.
In second iteration,
A[0] becomes 0.
In third iteration,
A[3] becomes 0.
In 4th iteration,
A[0] becomes 0. However, it was 0 before too.
In 5th iteration,
A[1] becomes 0. However, it was 0 before too.
At Last, list A is like :
[0,0,3,0,1]
0
I’m sorry, I don’t get it :(
Could you please explain this in other way?
0
Посмотри вот этот код. Добавил выводы для наглядности. Проследи за тем, как меняется массив после каждой итерации
A=[1,2,3,4,1]
for n in A:
print(n)
print(A[n])
A[n]=0
print(A[n])
print(A)
0
спасибо большое, я разобралась!)