+ 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?

22nd Oct 2020, 11:02 PM
Solus
Solus - avatar
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
23rd Oct 2020, 12:39 AM
Ayush Kumar
Ayush Kumar - avatar
0
I've answered a similar question before. You might check out: https://www.sololearn.com/Discuss/2546844/?ref=app
23rd Oct 2020, 2:09 AM
你知道規則,我也是
你知道規則,我也是 - avatar