16/18 general word choice question


#1

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?


#2

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


#3

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


#4

It’s a variable name


#5

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


#6

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


#7

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.


#8

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


#9

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