[Tutor] (no subject)

spir denis.spir at gmail.com
Sat Mar 22 14:30:39 CET 2014


On 03/21/2014 09:57 PM, Jerry Hill wrote:
> On Fri, Mar 21, 2014 at 3:25 PM, Gary Engstrom <gwengstrom at yahoo.com> wrote:
>> I am trying to understand function fibc code line a,b = b, a + b and would
>> like to see it written line by line
>> without combining multiply assignment. If possible. I sort of follow the
>> right to left evaluation of the other code.
>
> Sure.  a,b = b, a+b is equivalent to:
>
> new_a = b
> new_b = a + b
> a = new_a
> b = new_b
> del new_a
> del new_b
>
> That is, we first evaluate everything on the right hand side of the
> equals sign, then assign those values to a and b.  Then we get rid of
> the temporary variables, since the original statement didn't leave any
> temporary variable floating around.

In other words, it is like
	a = b ; b = a+b
performed *in parallel*. Another way to write it is:
	old_a = a
	a = b
	b = old_a + b

d


More information about the Tutor mailing list