Using strings in lists in functions


#1



https://www.codecademy.com/courses/python-beginner-nzzVa/3/5?curriculum_id=4f89dab3d788890003000096
Okay... I am creating another one, I AM STUCK I HAVE BEEN FOR... Hmm lets see... 2 - 2.5 WEEKS

Please help.

Error:

Traceback (most recent call last):
  File "python", line 6, in <module>
  File "python", line 4, in join_strings
AttributeError: 'str' object has no attribute 'append'


Rage meter: :rage: :rage: :rage: :rage: :rage: :rage: :rage: aka 7/10


code:

n = ["Michael", "Lieberman"]
def join_strings(words):
    result = ""
    words += result.append
    return result
print join_strings(n)


I am so stuck i just want to stop coding... PLEASE HELP MEEEEEEEE

'Kay?


I understand.... WaitForIt! ... ... ... NOTHING! YAY and now I'm raging :) The lesson is: Using strings in lists in functions
#2

.append() is a method for adding elements to lists, not strings

use + to join strings

if you need more help, post an updated version of your code


#3

n = ["Michael", "Lieberman"]
def join_strings(words):
    result = ""
    words += result
    return result
print join_strings(words)

Here is the updated version.


#4

here:

print join_strings(words)

you should supply n as argument, which then gets copied into the function parameter words

here:

words += result

words is a list, to which you add an empty string? Then you return the empty string

you should loop over words to get each word, which you can then add to result.


#5

I figured it out :slight_smile: thanks.!!


#6