Create a function with a local variable. Show what happens when you try to use that variable outside the function. Explain the results.
def func():
name="John" #local variable
print("Hello "+name)
func()
print(name) #this line causes an error since the variable name is defined locally in the function func
#and therefore it cannot be used outside the function
Comments
Leave a comment