Code Doesn't Work, Don't Know Why


#1



https://www.codecademy.com/courses/python-beginner-nzzVa/3/5?curriculum_id=4f89dab3d788890003000096#


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:
        result.append(item)
    return result


print join_strings(n)


#2

result.append(item)

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

how does append work?


#3

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


#4

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 ?


#5

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

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


#6

from lesson example:

If you call the function

join_strings("Hello", "there")

then it should return "Hellothere"

Does it make sense?

Hint

print 'a'+'b' # prints ab


#7

result += word
Got it! Thank you!


#8

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


#9

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