Strings in Function - Explanation


Can someone explain to me why you use return s instead of return n? In the function, n is not related to s in any way.

Why is it not: return n + 'world?

n = "Hello"
# Your function here!

def string_function(s):
    return s + 'world'

print string_function(n)


You return s because for that function, s is whatever is passed to it. You didn't have to pass the variable n to string_function, you could have passed the string, "Hola". However, if you did that, the result would still be "Hello world" because you are using n + 'world'.


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