0
I'm unable to understand the output .
a=[1,1,2,3,5,8] for a[1] in a: pass print(a)
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!
+ 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!!😊
+ 2
Tijan yes
0
𝕊𝕆𝕌𝕄𝕐𝔸 𝕊𝔸ℍ𝕌 so its like incrementing for every loop