[Edu-sig] Crunchy Fibonaccis

Tim Peters tim.peters at gmail.com
Fri Jul 28 02:38:17 CEST 2006


[Andre Roberge]
> Is the "order of operation" (i.e. first evaluated is the left-most
> one) always guaranteed to be that by Python?  Or is it only guaranteed
> by the current CPython version?...

It's definitely Guido's /intent/ that "left to right" be strictly
followed in all Python implementations, although I'm not sure the
language reference manual states this strongly enough that someone
from Mars could pick that up.

> I seem to recall, from many years in the past, that some language (C,
> I believe...) allowed
> statements like:
> i = 1
> a = 2*i++  +  i++
> but that the order of execution (i.e. which "i++" is executed first)
> could not be guaranteed...

Most languages don't define order of evaluation (C, Fortran, Scheme,
...).  This was to give optimization a chance to reorder operations
for low-level machine efficiency.  Python is so far from the HW that
it doesn't really matter ;-)

> (Quiz: what is "a" equal to? )

Not defined in C.


More information about the Edu-sig mailing list