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

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
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.
<In what way does your code behave incorrectly? Include ALL error messages.>
Traceback (most recent call last):
File “python”, line 10, in
File “python”, line 6, in join_strings
AttributeError: ‘str’ object has no attribute ‘append’

<What do you expect to happen instead?>

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

```python

n = [“Michael”, “Lieberman”]

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

print join_strings(n)

<do not remove the three backticks above>

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

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

1 Like