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!
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
Oren Schindler
Python Web Development Techdegree Student 1,098 PointsFor Loop
I’m not clear why ‘player’ is used in the for loop? It was never defined. Why wouldn’t you use For ‘name’in players print(“Player {}: {}”.format(player_number,name))
1 Answer

Chris Freeman
Treehouse Moderator 68,332 PointsFound this video in the Practice Creating and Indexing Lists
The player
gets defined in the for
loop.
The line for player in players:
sets the variable player
to each value in players
, in turn.
Is common format to use:
for single_loop_variable in many_items:
# like
for car in cars:
# or
for ox in oxen:
Post back if you need more help. Good luck!!!
Oren Schindler
Python Web Development Techdegree Student 1,098 PointsOren Schindler
Python Web Development Techdegree Student 1,098 PointsThank you, that makes sense. Why would one define a new variable “player” if there exists one that satisfies (“name”)?
Chris Freeman
Treehouse Moderator 68,332 PointsChris Freeman
Treehouse Moderator 68,332 PointsNot sure I’m following.
The
for
loop variable name is typically not used outside of the loop and is distinctly named so it’s easy to follow within the loop.If
name
is used outside the loop, it’s value would be overwritten by the loop: