Why is the output [1,8,2,3,5,8] instead of [1,1,2,3,5,8]? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why is the output [1,8,2,3,5,8] instead of [1,1,2,3,5,8]?

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

29th Mar 2023, 3:13 PM
Harsirat Singh Jouhal
Harsirat Singh Jouhal - avatar
4 Answers
+ 5
Loop copying elements list elements into a[1] so list is modified by loop.
29th Mar 2023, 3:18 PM
Jayakrishna 🇮🇳
+ 5
Harsirat Singh Jouhal Found previously posted same question. Explanation is already there. Hope it helps to understand.. https://www.sololearn.com/Discuss/3173641/?ref=app Go through this and reply if anything not understood..
29th Mar 2023, 3:30 PM
Jayakrishna 🇮🇳
+ 2
Thanks
29th Mar 2023, 3:32 PM
Harsirat Singh Jouhal
Harsirat Singh Jouhal - avatar
+ 1
Can you please explain more about this?
29th Mar 2023, 3:24 PM
Harsirat Singh Jouhal
Harsirat Singh Jouhal - avatar