I am reading the book Python Programming for the Absolute Beginner by Mike Dawson and I was struck by a question that I had regarding functions.
Observing the code below
def func_1():
name = input('What is your name?')
def func_2():
print(name)
func_2()
I know that I cannot call the variable name in function 2 as it is local to function 1.
However, why can I call a function inside another function and then find the value of the user's input as such below?
def func_1():
name = input('What is your name?')
return name
def func_2():
user_input = func_1()
print(user_input)
func_2()