Need Clarification on python exercise


So I was doing the “Learning Python” course from codecademy and this one exercise confused me a little…

so the direction was:


Write a function called string_function that takes in a string argument ( s ) and then return s that argument concatenated with the word 'world' . Don’t add a space before world !

and the answer was:
n = “Hello”

Your function here!

def string_function(s):
return s + ‘world’

print string_function(n)

so what i want to know is that how does “s” have a set value of “Hello” and if you do s + world, it comes out to be Hello World, also the fact that you print string_function(n) although, n was never an argument in string_function… im confused can someone help?


But it is,

There is your n.

Recall that n is already pointing to set string object. It is that string that gets passed to s, the parameter of the function. The output should be, HelloWorld. No space.


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