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

Bengt Richter bokr at oz.net
Tue Nov 12 07:47:57 EST 2002


On Tue, 12 Nov 2002 12:09:56 +0000 (UTC), Duncan Booth <duncan at NOSPAMrcp.co.uk> wrote:

>Bernhard Herzog <bh at intevation.de> wrote in 
>news:6q7kfjau4f.fsf at salmakis.intevation.de:
>> 
>> python -c "a = b = 1L; exec('while 1: print a; a,b=b,a+b')"
>> 
>> It would be nice to get rid of that exec, too...
>
>You could get rid of the unnecessary parentheses after the exec. And as for 
>the whitespace, are you trying to make it readable or something?:
>
>  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? Does that mean it effectively assumes a semicolon is the
same as a newline and indent to the same level as the previous statement, until
it finds an actual newline?

Regards,
Bengt Richter



More information about the Python-list mailing list