Computer Science, asked by jinia19, 1 month ago

for a in [1,2,3]: in this statement what is in​

Answers

Answered by lavanya3602
1

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:

  1. it is a collection different datatypes
  2. list is mutable(changable)
  3. allows duplicate items(members)
  4. lists are written in square brackets. [ ]
Similar questions