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

Bengt Richter bokr at oz.net
Tue Nov 12 09:50:53 EST 2002


On 12 Nov 2002 14:56:42 +0100, Bernhard Herzog <bh at intevation.de> wrote:

>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.
>
Well, I knew all that, except I didn't think you could do it in the context
of a complex statement suite (i.e., after a colon). I attributed its working
to exec because I thought it wasn't otherwise allowed after a colon. Bad assumption.

Well, good to get that straight (though maybe not for readability, if I'm tempted
to pack too much on a line ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list