16/18


#1

I’ve been getting through the lists and functions sections kind of okay, but one thing eludes me. What is the first variable in the for loop referring to? I’ve included the script below. “word” has never been referenced before, but I can write “for word in words:” and python know to use everything in “n”. How does this work? I can use pretty much whatever variable I want to, so it seems, in a for loop and it will somehow know to reference the list at the top. This doesn’t make sense to me. Thanks for the help!

n = [“Michael”, “Lieberman”]

Add your function here

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

print join_strings(n)


#2

It is actually declared in the expression, and acts as a temporary holder of the iterator.

Think in terms of plural, words, and singular, word, which will take on each term in words, in turn. Being a list, the order will be preserved.


#3

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