Python call inner function inside another function
<p>Edited!
I wanted to reference inner function return value outside of outer function, and actually inside of another function.</p>

<p>Example:</p>

<pre><code>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())
</code></pre>

<p>Now I want to create a new function and I need the return value of m2() to be in it:</p>

<pre><code>def m3():
    pre_solution = m2()
    m3_solution = pre_solution*3
    return m3_solution

print(m3())
</code></pre>

<p>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.</p>

<pre><code>def m3():
    x= 'A'
    y= 'B'
    pre_solution = x+y
    m3_solution = pre_solution*3
    return m3_solution

print(m3())
</code></pre>

<p>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.</p>

<p>Thank you</p>