Comprehension Check
Take a look at the code below:
def function_1():
my_var = "Hello"
print(my_var)
def function_2():
print(my_var)
function_1()
function_2()
In this code, function_2() is attempting to print the
value of my_var. When it tries to execute the print
statement, an error generates, informing us that
'my_var' is undefined. Why does this error occur?
Take a look at the code below:
def function_1():
my_var = "Hello"
print(my_var)
def function_2():
print(my_var)
function_1()
function_2()
In this code, function_2() is attempting to print the
value of my_var. When it tries to execute the print
statement, an error generates, informing us that
'my_var' is undefined. Why does this error occur?