Using strings in lists in functions - Attribute error:'str' objects has no attribute 'append'


#1



exercise 16 in using strings in lists in functions ***

****NOTE**** I recently found an identical topic. I've tried to delete this post but cannot find how to do so.

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 would have expected the function to return result as "MichaelLieberman". The error message makes me think you can't use append to concatenate strings, but what do I know.
When I try changing the result to a list ie. result=[""] the append function works, but obviously that's not what the console wants to see


n = ["Michael", "Lieberman"]

def join_strings(words):
    result=""
    for word in words:
        result.append(word)
    return result


print join_strings(n)


#2

You could instead post the detailed solution to this, and mark as solved/ You could be helping someone else.


#3

the .append function cannot be applied to strings. In order to concatenate a word from each iteration, you can use the regular + operator as applied to strings ie.

result += word

I'd imagine that the exercise includes the word "append" to make this clear once you've made the mistake


#4