Using Strings in Lists in Functions


Hello, I am struck on this.

I keep getting this message File "python", line 7
SyntaxError: 'return' outside function

I then tried moving the "return result" line around a bit but nothing works.
Please help.

n = ["Michael", "Lieberman"]

Add your function here

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

print join_strings(n)

Thank you.


Replace this line with your code.


I think there is problem with your indentation.
Python uses indentation to structure code blocks.
Without it,It will throw an error.
Follow this syntax...

def Yourfunction(someparameter):
    #for loop
        #expression inside the for loop
    #return the final value

also a short read on indentation-
Indentation in Python

do reply if it solved the issue or not!


It works.

Thank you.


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