16/18 general word choice question


I had trouble with the code, so I looked at the correct answer, which was provided as:

n = [“Michael”, “Lieberman”]

def join_strings(words):
result = ""
for word in words:
result += word
return result

print join_strings(n)

Why can we use “for word in words” instead of “for item in words” or “for i in words”? Basically, how does Python treat “word” in this instance? Are word, item, and i interchangeable?


That’s where you’re telling it that information - where the values should go


Can I use “word” anytime I want to refer to a string? Or, is “word” allowable here because I defined the parameter as “words”?


It’s a variable name


If my parameter were “names” instead of “words,” could I still write “for word in names” or would I write “for name in names”?


It creates a variable by that name. No meaning is derived from the name itself


Thank you! That is what I couldn’t figure out. Does “item” have a meaning in Python? I have seen that appear in exercises without setting the variable.


Not even by convention, if you have something in a container, you’ll probably say “item” for the containees. Items in a list. Items in a basket

It’s generally a good idea to pluralize the name of a container. Here are my cars, here are my horses, and refer to each element by car, horse… word


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.