Using strings in lists in functions code error


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)) :
    return result

print join_strings(n)


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]


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


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