beginner question fibonacci

ralobao at gmail.com ralobao at gmail.com
Sun Jul 17 09:56:46 EDT 2005


The case is that Python in attribution commands solves first the right
side, so he atributes the vars.

So the a+b expression is executed first.

Joon escreveu:
> >>> # Fibonacci series:
> ... # the sum of two elements defines the next
> ... a, b = 0, 1
>  >>> while b < 10:
> ...       print b
> ...       a, b = b, a+b
> ...
> 1
> 1
> 2
> 3
> 5
> 8
>
>
>
>  >>> a, b = 0, 1
>  >>> while b < 10:
> 	print b
> 	a = b
> 	b = a+b
> 
> 	
> 1
> 2
> 4
> 8
> 
> Why a, b = b, a+b isn't a = b; b = a+b ?




More information about the Python-list mailing list