https://www.codecademy.com/courses/learn-python/lessons/a-day-at-the-supermarket/exercises/stocking-out-?action=resume_content_item
Hi,
On Python 2, chp 5 List & Dictionaries.
I don’t get where the “Item” variable is coming from for the Loop.
Thanks,
Regards,
Laki
You need to call the function with an argument to pass to the parameter food: For example,
print(compute_bill(shopping_list))
Now, the list, shopping_list goes in wherever you see food, and item is the iterator variable that is used when that list is iterated over.
Note on nomenclature:
If you have a list, my_ list = [‘a’, ‘b’, ‘c’]
… then by the magic of Python’s for - in expression
for thing in my_list:
print(item)
'''Output:
a
b
c
'''
… every time the loop executes, the variable thing is assigned a new value, in this case, first ‘a’, then ‘b’, then ‘c’.
Here, the list, my_list is referred to as the iterable object (or simply iterable), while the variable thing is referred to as the iteration variable.
2 Likes