[Tutor] Fibonacci Series
Dominik George
nik at naturalnet.de
Sun Nov 24 11:40:06 CET 2013
Hi,
> a, b = b, a +b
> a = b = 1
> b = a + b = 1 + 1 = 2
Your issue is that you interpret the assignment wrong. You seem to think
that it assigns b to a and THEN a+b to b, which is not the case. The
right side of the assignment creates a tuple, and the left side unpacks
it. It is the same as:
t = (b, a+b)
a = t[0]
b = t[1]
You see that a has not been assigned yet when the second part is calculated.
Cheers,
Nik
--
* mirabilos is handling my post-1990 smartphone *
<mirabilos> Aaah, it vibrates! Wherefore art thou, demonic device??
PGP-Fingerprint: 3C9D 54A4 7575 C026 FB17 FD26 B79A 3C16 A0C4 F296
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 905 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/tutor/attachments/20131124/55695538/attachment-0001.sig>
More information about the Tutor
mailing list