Can python find fibonacci series in a single line of code?

Bernhard Herzog bh at intevation.de
Tue Nov 12 08:56:42 EST 2002


bokr at oz.net (Bengt Richter) writes:

> On Tue, 12 Nov 2002 12:09:56 +0000 (UTC), Duncan Booth <duncan at NOSPAMrcp.co.uk> wrote:
> >
> >  python -c "a=b=1;exec'while+1:print+a;a,b=b,a+b'"
> >
> >Who ever said Python programs need whitespace!
> 
> I didn't know exec would parse semicolons that way (I hardly ever use
> it). But is that new with 2.2?

That's been valid Python syntax for ages. The first python version I
used was 1.3 and I don't think I ever used a Python version that didn't
support semicolons as optional statement terminators. In fact,
Misc/HISTORY reveals that this was introduced in 0.9.2.

It's got nothing to do with exec in particular, BTW. It's a standard
feature of the Python syntax.

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                           http://www.mapit.de/



More information about the Python-list mailing list