Python For Loops - 7/11

When row[7] is actually the user_rating column of which we are trying to calculate the sum, then why don’t we take the column as a variable such as for column in apps_data ??

Not able to understand your question @mursuljamil. Can you rephrase it, please?

Read line 4 & 5 in the paragraph on the left side of the picture. And keep in mind I am talking about the 8th element (index # 7) in the apps_data which is rating. Now read the following question:

When row[7] is actually the user_rating column (as mentioned in the paragraph)and we are trying to calculate the sum of it, then when making a loop why don’t we take it as - for column in apps_data and not - for row in apps_data ??

Hi,

when you’re doing a for loop, the variable could be named anything you want.

In this case:

for a in apps_data[1:]:
for row in apps_data[1:]:
for column in apps_data[1:]:

They are all the same. You can try it out!
You are still looping the row of the list.

A for loop of a list would look like:

for [row, but you can name it whatever you want] in [name of your list]:

Hope this helps! check out
https://www.dataquest.io/blog/python-for-loop-tutorial/#:~:text=In%20the%20context%20of%20most,each%20item%20in%20the%20list.

for more info.

The iterative variable name can be anything you want, it won’t impact the for loop. It’s just a temporary variable named used for writing loops. Like @cy.ericson explained, the variable name can be anything you want, as long it follows Python variable naming conventions.