16/18 Type error: cannot concatenate


#1

https://www.codecademy.com/courses/learn-python/lessons/lists-and-functions/exercises/using-strings-in-lists-in-functions?action=lesson_resume

Traceback (most recent call last):
File “python”, line 11, in
File “python”, line 6, in join_strings
TypeError: cannot concatenate ‘str’ and ‘list’ objects

I really don’t understand what this type error is saying.

n = [“Michael”, “Lieberman”]

Add your function here

def join_strings(words):
result = ""
for i in words:
result = result + words
return result

print join_strings(n)


#2

here:

result = result + words

result is a string, and words is a list. which results in a type error given we can’t concatenate string and list

we build a loop, so we get the string elements from the list so we can concatenate them to our results string, but which variable should we use to achieve this?


#3

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