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

week_number <--- is that a variable?

is week_number a variable? How would week, week_number and travel_expenses be connected and or how would the loop (for week in travel_expenses) know what information to loop through if week_number is a variable and not a function?

I don't even know if my question makes sense, that's how confused I am

1 Answer

Steven Parker
Steven Parker
231,268 Points

You're exactly right, "week_number" is indeed a variable. So is "week", but they are not connected. But both of them are used to hold a number.

The term after the word "in" tells a loop what to loop through. it's called the "iterable". In this loop the iterable is "travel_expenses", which is a variable that contains a list of values. So the loop goes through the list, and assigns each value (one at a time) to "week".

Does that clear it up? Add a comment if you need more help with this.

Stephanie Tabor
Stephanie Tabor
2,944 Points

When I was watching the video, I had the same question. Does week_number = 1 as in one list in the travel_expenses iterable? Or does week_number = 1 literally mean the number 1?

Steven Parker
Steven Parker
231,268 Points

A reference to another variable would have to have the variable's name. A literal "1" always represents just the number 1.