+ 2
Python - What is the meaning of this for statement?
a = [0,1,2,3] for a[3] in a: # What does a[3] do? print(a[-1]) #output: 0 1 2 2 How did we get to this output?
2 ответов
0
Ok acctuly when a loop run I think it runs like
for var = elementFronIter in range Elements
So as per the condition a[3] is assigned by the list element of a .
In first run a[3] = 0
{ If it a[3] would be a variable we would be using its value anywhere }
In second run a[3] = 1
In 3rd run a[3] = 2
Now in 4th run as it is allready 2 so 2 comes again.
This is how it would be working I guss 🤔
But not sure still
I told this because we know that e know that lists mutable data types
0
I've answered a similar question before. You might check out: https://www.sololearn.com/Discuss/2546844/?ref=app