Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Introducing Lists Using Lists Multidimensional Lists

what does "week" in sum(week) mean in Craig's code?

When Craig writes out his code to show the amount of expenses he incurred for 3 weeks respectively, what is the word week in sum(week) in the "for" block doing? How is it related to the "week" in "for week in travel_expenses"?

Here's the code:

travel_expenses = [
    [5.00, 2.75, 22.00, 0.00, 0.00],
    [24.75, 5.50, 15.00, 22.00, 8.00],
    [2.75, 5.50, 0.00, 29.00, 5.00],
]

print("Travel Expenses:") 
week_number = 1 
for week in travel_expenses:
    print("* Week #{}: ${}".format(week_number, sum(week)))
    week_number += 1

Thanks in advance 😁

1 Answer

Josh Keenan
Josh Keenan
19,652 Points

Week is referring to the item currently being used by your for loop.

for week in travel_expenses:

In this context week will be one of the arrays of numbers in the variable travel_expenses. You can use any name* for whatever it is you wish to go over with your for loop.

*except for reserved words like print or while.

great thanks!