Functions: Fundamentals: Knowing what the individual items in a list are called

ratings = [‘4+’, ‘4+’, ‘4+’, ‘9+’, ‘12+’, ‘12+’, ‘17+’, ‘17+’]

content_ratings = {}

for rating in ratings:

E.g. for the above code, how am I meant to know that I should use ‘rating’ in the for rating in ratings part. What defines each individual item in the list here as a ‘rating’ ?

rating is just the name of the iterator that points to a particular index in the list. It starts at the first index and moves onto the next index at each iteration till it reaches the end.

The name of the iterator is upto you. You could have it as -

for r in ratings:


for asldkjlk in ratings:

and both would be valid. But calling it rating is much better since it’s descriptive and easy to read - it’s a rating in a list of ratings.

1 Like

Thank you! That’s really helpful!