Python paradigms

Oleg Broytmann phd at phd.russ.ru
Sun Apr 9 12:37:48 EDT 2000


On Sun, 9 Apr 2000, Fredrik Lundh wrote:
> Oleg Broytmann wrote:
> >    blah = ((foo() and [poo()]) or [boo()])[0]
> >
> >    In C, "foo() ? poo() : boo()" will not call boo() if foo() returns
> true;
> > but in Python, you'll have a side-effect of calling boo() even if foo()
> > returns true - what is wrong, usually.
> 
> did you try running the code?
> 
> python's "and" and "or" operators doesn't evaluate the
> second argument unless they really have to...

   Yes, I missed that, sorry.
   Anyway, it is strange (not to say "ugly") construct; I prefer not to see
it in a code...

Oleg.            (All opinions are mine and not of my employer)
---- 
    Oleg Broytmann      Foundation for Effective Policies      phd at phd.russ.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list