Iteration Variable Doubt

Hi everybody,

I’ve started the course one month ago and I’ve a question regarding the iteration variable.

When we run a for loop in the course (this mission for example) we use an iteration variable that is not previously define such as apps, row, value and element.

Are they a sort of default variable already defined in Python? If so there is a sort of dictionary or a list of those default variable.

Thank you very much for the attention,

Hi @mengoli.stefano1994

When you use a for-loop the variable is ‘defined’ as soon as the loop starts. And because it belongs to the scope of the loop, you cannot access it before the loop has started or after the loop has finished. I hope the linked aticle is not too technical, but it should give you a general idea of scopes.


1 Like

Hi @mengoli.stefano1994:

You may find this article that I answered useful.

Hope it helps!

@mengoli.stefano1994 The variable you define as iteration variable that is not any default variable in python, so there is no dictionary or list of that sort, you can give the name as you wish and according to your content(if you want to make your code more readable and understandable), it can be a, b, c, d, i, app, mengoli, bla , bla, bla etc. It’s completely up to you. And you can access the variable just inside the loop, for which the variable is created. The variable can’t be accessed outside the loop.
See, I’ve used “row” instead of “app”, It worked perfectly.
Similarly you can use :

for stefano in apps_data[1:]:

   price = stefano(row[4])

for raisa in apps_data[1:]:

   price = raisa(row[4])

Hope it makes sense.
Happy coding. :heart:

1 Like