Re: indentation...

Steven Miale (smiale@cs.indiana.edu)
Sun, 17 Jul 1994 13:03:28 -0500

In article <2e28a327.pcg2@aurora.pcg.com>,
Ron Forrester <rjf@aurora.pcg.com> wrote:
>def fib(n):
> a, b = 0, 1
> while b <= n:
> print b,
> a, b = b, a+b
>
>
>What are the first ('a, b = 0, 1') and last ('a, b = b, a+b') lines
>doing?

It's a way of doing more than one assignment at once. The first statement
simply assigns 0 to a and 1 to b.

When this syntax is used, the entire RHS is evaluated first, then assigned.
So 'a, b = b, a' swaps the value of a and b.

What is really happening is that the expressions '0,1' and 'b,a+b' create
tuples; the LHS ('a,b' in both cases) unpacks the tuple.

Steve

-- 
Steven Miale [smiale@cs.indiana.edu] HTTP://cs.indiana.edu/hyplan/smiale.html