Code Doesn't Work, Don't Know Why


Traceback (most recent call last):
File "python", line 10, in
File "python", line 6, in join_strings
AttributeError: 'str' object has no attribute 'append'

I'm not sure why my code doesn't work. Please help!

n = ["Michael", "Lieberman"]
# Add your function here
def join_strings(words):
    result = ""
    for item in words:
    return result

print join_strings(n)



what did you want to do in this line of code?

how does append work?


It's to append each string in the list to "result."


append adds each element to a list.

result is a string value not a list.

Error: AttributeError: 'str' object has no attribute 'append'

consider how can you add two string ?


> Iterate through the words list and append each word to result.

Ok, that's what the instructions say, so how would I do that?


from lesson example:

If you call the function

join_strings("Hello", "there")

then it should return "Hellothere"

Does it make sense?


print 'a'+'b' # prints ab


result += word
Got it! Thank you!


append will work, BUT the empty list is created with [], not quotes


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