title: Dynamic Variable assignment in Python
body: <p>I am testing a python script, where I have to constantly store the old values of 2 variables and then return them through a function. For this I took fibonacci series as an example:</p>
  
  <pre><code>def fibonacci(n):
    a=0;b=1;cnt=0;
    while True:
      if (cnt &gt; n):
        return;
      yield a;
      c=b;b=a+b;a=c;
      cnt +=1;
  
  fib=fibonacci(5)
  for x in fib:
    print(x,end=" ")
  </code></pre>
  
  <p>Everything works perfectly as expected here, and the output is also as expected. I however tried to write it in a different way, where instead of using an extra variable "c", I can still do the swap of old values efficiently, and I practically bumped on this (though have no idea how the assignment is working here) :</p>
  
  <p>Instead of the line:</p>
  
  <pre><code>c=b;b=a+b;a=c;
  </code></pre>
  
  <p>Used:</p>
  
  <pre><code>a,b=b,a+b
  </code></pre>
  
  <p>So a detailed explanation will be appreciated.</p>