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 trialbarrysw
2,110 Pointslost on FOR syntax
how to interperate the Help() info, is there a help for the help?
the syntax is not understood from this
The "for" statement
The "for" statement is used to iterate over the elements of
a sequence
(such as a string, tuple or list) or other iterable object:
for_stmt ::= "for" target_list "in" expression_list ":"
suite
["else" ":" suite]
What do I need to do if the above is in comprehensible ??
def loopy(items):
for(items):
print(itmes)
if items = "STOP" : break
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsMore info on for
loops in the Python wiki, Python tutorial, and the reference doc.
The syntax has 4 parts:
- keyword for
- loop variable, say, item
- keyword in
- an iterable or container object (such as a list, string, dict or other iterable)
In your case, the iterable is items
, you need to provide a loop varaible. This is sometimes a "singular" for of the iterable name.
def loopy(items):
for item in items: # each time through loop take one element from 'items', assign it to 'item'
print(item)
if item == "STOP:
break