7/18: Strings In Functions. Help my understanding please


#1

Hi everybody,
I have just completed this task yet am struggling to understand it nevertheless :confused:


n = "Hello"

#Your function here!

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

print string_function(n)

So my code worked fine, but I don't understand why it isn't :

  return n + "world"

as opposed to :

  return s + "world"

:checkered_flag: Thanks :checkered_flag:


#2

Try this:
n = "Hello"

Your function here!

def string_function(s):
s = s + str("world")
return s

print string_function(n)


#3

My code worked, it's just that I don't understand why its 's' as opposed to 'n'.


#4

Never mind,
I understand now, I believe it's because the n is a global list as opposed to a local list (which in this case was s).


#5

You got it! :grinning: