abjer / sds2019

Social Data Science 2019 - a summer school course
https://abjer.github.io/sds2019
46 stars 96 forks source link

What do I write after the for in a for loop? #2

Open Emilie-student opened 5 years ago

Emilie-student commented 5 years ago

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?

abjer commented 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.