Why is it showing me an error and displaying "waynes world"


#1


#2

Why would you give your function a parameter and then overwrite the parameter value?

given the function a parameter allows you to use the function for different strings, which is really neat


#3

im still learning, how else would you suggest i do it?


#4

not overwriting the function parameter so you can pass different strings as argument of function call


#5

and by that you mean use something else as a variable?
Thanks in advance


#6

lets add another line of code:

print string_function(n)
print string_function("Waynes")

i added another function call with "Waynes" as argument, yet it produces Helloworld as output, wouldn’t it be nice if the function outputs Waynesworld, that your function works for multiple strings?


#7

forgive my ignorance, but how exactly would that help?
what i did was:

def string_function(s)
f = “world”
return f + n
print string_function(n)

are you implying that i could’ve changed the argument to “world” instead of keeping it as s


#8

write a function called string_function takes in a string argument (s) and then returns that argument (referring to s) with word 'world'

so we need to return s + "world", and ensure we do not change the value of s (like you did in your first code)

s will gets its value from the argument at function call

using parameters and arguments allows you to do the same task with slightly different values. Making your program so much more flexible


#9

ohh alright! thanks! much appreciated!
One last question if I may; does calling a function mean using it as such : string_function = a + b, or does it mean returning it?


#10

these two lines:

print string_function(n)
print string_function("Waynes")

are function calls, calling a function will cause it to execute


#11

thank you! :slight_smile:
you’ve been really helpful i really appreciate it


#12

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