Edited! I wanted to reference inner function return value outside of outer function, and actually inside of another function.
Example:
def m1():
def m2():
x= 'A'
y= 'B'
pre_solution = x+y
return pre_solution
pre_solution = m2()
m1_solution = pre_solution*2
return m1_solution
print(m1())
Now I want to create a new function and I need the return value of m2() to be in it:
def m3():
pre_solution = m2()
m3_solution = pre_solution*3
return m3_solution
print(m3())
I get an error that m2 is not defined. I need to get pre_solution value without using copy and paste(since the real code has many more lines in it). Here is my current work around but I wanted to see if there was an easier way.
def m3():
x= 'A'
y= 'B'
pre_solution = x+y
m3_solution = pre_solution*3
return m3_solution
print(m3())
I'm doing it for an assignment that uses autograder and only evaluates code inside of the functions, not the global scope, m1() and m3() are going to be evaluated but if I put m2() into global scope it won't be. Hope it makes sense. It's my very first question on here.
Thank you
Do you want somthing like this :
This method helps you to get the variable inside outer functions.