def change(s):
s = s + "!"
word = "holiday"
change(word)
print word
how come the output of this is “holiday” instead of “holiday!”? Is it because the 3 line of codes are outside the function? If so, why would it matter if it’s outside the function since it’s after the change function?
Try this:
Use it like this:
Or like this:
Be aware that any modifications you do to a parameter string inside a function will not be seen outside the function, as the
sparameter in the function is local to the scope of the function, and any changes you do (like in the code in the question) will only be visible inside the function, not outside. All function parameters in Python are passed by value.