Unusual problem with multiple return in Python
<p>When I call the function "<code>G()</code>" which returns two values: <code>p_T</code> and <code>q_T</code> twice (see below) but using the same style, that's, <code>P_T, neg = G(); U, Ign = G()</code> and print sums of <code>P_T</code> and <code>U</code>, I get two different answers! Another thing is that both answers are incorrect!</p>

<p>I have only included part of the code which can simply aid in explaining the idea. The block of statements within the function <code>G()</code> under the for loop is executed N times as the loop suggests. Is there something being compromised by global variables declaration?</p>

<p>Any suggestion of what is wrong and how to fix it is appreciated!</p>

<pre><code>def G():
    global p_T; global q_T

    for n in range(N):
        p_T = U_T(EvolveU_T(p_T))
        q_T = V_T(EvolveV_T(q_T))

    return p_T, q_T

P_T, neg = G()
print sum(P_T)
U, Ign = G()
print sum(U) 
</code></pre>
