Question #237082

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.


Expert's answer

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.



LATEST TUTORIALS
APPROVED BY CLIENTS