Create a function that takes an argument . Give the function parameter a unique name . Show what happens when you try to use that parameter name outside the function. Explain the results.
friend="Tosh"
def Birthday(friend):
print("Happy Birthday " + friend + ".")
Birthday("John")
print(friend)
When a parameter has the same name as a name defined outside the function, the function will not use the variable defined outside, it will only referenced the value that was passed to the parameter. So parameters will be used over variables of the same name within a function.
Comments
Leave a comment