0

I'm unable to understand the output .

a=[1,1,2,3,5,8] for a[1] in a: pass print(a)

17th Jun 2020, 5:34 AM
Rohit Raj
Rohit Raj - avatar
4 Respuestas
+ 3
a=[1,1,2,3,5,8] for a[1] in a: print(a) pass print(a) #Run this you'll understand!
17th Jun 2020, 6:07 AM
minirkk
minirkk - avatar
+ 3
for a[1] in a: Will work like assigning value to a[1] each time from list a So for a[1] in [1,1,2,3,5,8]: Starting from >>index 0 a[1] is assigned a[0] i.e a[1]=1 => a=[1,1,2,3,5,8] >>index 1 a[1] is assigned to a[1] a[1]=1 => a=[1,1,2,3,5,8] >>index 2 a[1] is assigned to a[2] So a[1]=2 => a=[1,2,2,3,5,8] >>index 3 a[1] is assigned to a[3] So a[1]=a[3]=3 => a=[1,3,2,3,5,8] >>index 4 a[1] is assigned to a[4] So a[1]=a[4]=5 => a=[1,5,2,3,5,8] >>index 5 a[1] is assigned to a[5] So a[1]=a[5]=8 => a=[1,8,2,3,5,8] Hope you understand it well!!😊
17th Jun 2020, 7:38 AM
SOUMYA
SOUMYA - avatar
+ 2
Tijan yes
17th Jun 2020, 8:33 AM
SOUMYA
SOUMYA - avatar
0
𝕊𝕆𝕌𝕄𝕐𝔸 𝕊𝔸ℍ𝕌 so its like incrementing for every loop
17th Jun 2020, 8:01 AM
Tijan
Tijan - avatar