For loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

For loop

in question letters = ['a','b'] for l in letters: print(l) what does 'l' indicate? is l is constant or variable?

30th Jan 2017, 1:16 PM
Kausthubha K
Kausthubha K - avatar
4 Answers
+ 2
It's a variable. As the loop iterates through the array, it gets each element's value assigned to it one after another. First iteration: l = 'a', so when you print l, it prints 'a'. Second iteration: l = 'b', so it prints 'b'. If you added more elements it would continue the same way with the rest of them. Also, it doesn't have to be l, you can use any letter.
30th Jan 2017, 2:07 PM
Doc
Doc - avatar
+ 1
letters = ['a', 'b', 'c'] for l in letters : print(l) Right answer
25th Apr 2020, 10:20 AM
Shivam jaiswal
0
similar to for i in range(0,10) loops from 0 to 9 for l in letters loops from 0 to len(letters)
11th Feb 2017, 11:16 AM
Madhurima Chakraborty
Madhurima Chakraborty - avatar
0
letters = ['a', 'b', 'c'] for l in letters : print(l)
25th Jun 2019, 6:54 PM
Sudarshana Atapattu
Sudarshana Atapattu - avatar