Using .append Instead


#1


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

I want to know why I cant use .append to do this exercise. My code works when I use the result = result + words[item], but I get the error code below when I try to use the result.append(words[item]). Aren't the two lines doing basically the same thing? How can I use .append in this context.

AttributeError: 'str' object has no attribute 'append'


n = ["Michael", "Lieberman"]
# Add your function here

def join_strings(words):
    result = ""
    for item in range(len(words)):
        result.append(words[item])
       # result = result + words[item]
    return result

print join_strings(n)


#2

Because we already have a list. Our job is to extract the words from that list and concatenate them into a single string object (no space characters).


#3

what should be the exact code then.
i have tried so many codes but still confused in joining strings
can you please tell me how to join strings


#4

'string" + "string" # 'stringstring'

Notice that the + operator when used on two strings acts as a string join operation.


#5

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