for a in [1,2,3]: in this statement what is in
Answers
It means a is storing one element from that list for every iteration.
if you want to print what is a hold for every iteration.
for a in [1,2,3]:
print(a)
output:
1
2
3
Here i have printed the list that is holding in a
iteration1: a = 1 #here a is storing 1 from the list
jumps inside the loop and execute the statement that is printing a
so, a is printed and automatically incremented.
iteration2: a = 2 #here a is storing 2 from the list
jumps inside the loop and execute the statement that is printing a
so, a is printed and automatically incremented.
iteration3: a = 3 #here a is storing 3 from the list
jumps inside the loop and execute the statement that is printing a
so, a is printed and automatically incremented.
now, when you incremented there no other element in the list so it comes out from the list means for loop is terminated.
About the list:
- it is a collection different datatypes
- list is mutable(changable)
- allows duplicate items(members)
- lists are written in square brackets. [ ]