Open Emilie-student opened 5 years ago
The object x
refers to an element in y
. We could also have written for a in y
and then the elements of y
we instead call a
. Instead of x
we could also write something unrelated, e.g. for dog in cats
where dog
is an element of cats
.
After a for loop (i.e. after the colon) you write need to begin an indentation which is a new line where you press tab (or make four spaces). An example is as follow where the function my_script
is executed for each element x in y.
for x in y:
my_script()
BONUS info: this is the same you make if statements and define functions.
When I have to create a for loop, what do I write after the
for
?Ex.
for x in y:
What am I supposed to write instead of the
x
? And is it supposed to be related to the topic?