10/18 return function


I still don’t quite understand,
in this case why:

def list_funtion(x):
x[1] = x[1] + 3
return x

but not:

def list_function(x):
return x[1] = x[1] + 3

I guess I still don’t quite understand the return function.


return does literally what it says, it hands you something back

you can’t assign a variable and return on the same line. That is too many tasks at once. Its like me saying to you: write something on this piece of paper, and while you are writing i take the piece of paper back (return)

maybe including a function call would clarify return:

def list_funtion(x):
    x[1] = x[1] + 3
    return x

# call the function
# capture returned result in returned_result variable
returned_result = list_function([1,3,5])
# print the returned result stored in returned_result variable
print returned_result


Great reply, thanks.


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