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
Chris Johnson
3,001 PointsLoopy Function Example....What is this thing
I cant find the answer to this in any of the videos or forum posts and I am sure I just don't know enough knowledge to ask the right question so I apologize up front if this is obvious and I am just missing it.
In the Loopy function code challenge the block that solves the challenge is:
def loopy(items): for thing in items: if thing == "STOP": break else: print(thing)
My question is this ... what is "thing" called in this example. I determined that I could change "thing" to "poop" and that works too but I don't understand why I can just make up a name for this and python seems to know exactly what I am trying to accomplish. Thanks for any input this is really bugging me.
1 Answer
jcorum
71,830 PointsYou didn't give your code, but assuming it looks something like this:
def loopy(items):
# Code goes here
for item in items:
if item == "STOP":
break
print(item)
The thing the challenge is talking about is the current item in the items list. As you loop through the items, each one is temporarily placed in the item variable, and then you test to see if that item is STOP or not.
P.S., you don't need to name the variable item, as i do here. It could be thing, or n, or x, or whatever. E.g., for thing in items:
But usually coders use the singular of the list name. So item for a list items, etc.