Using strings in lists in functions code error


#1



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


I can't understand the error nor can I figure out the mistake in my code. If you have coded it correctly, please let me know the code. Thanks.
Error given is-
"Traceback (most recent call last):
File "python", line 10, in
File "python", line 6, in join_strings
AttributeError: 'str' object has no attribute 'append' "


n = ["Michael", "Lieberman"]
# Add your function here
def join_strings(words) :
    result = ""
    for i in range(len(words)) :
       result.append(words[i])
    return result


print join_strings(n)


#2

In your code result is defined as an empty string. The String class has no .append() method. For this purpose we must use concatenation.

result += words[i]

#3

Thanks a lot! :slight_smile: It made the code work and I understood my mistake there.


#4

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