Python complaints

Oleg Broytmann phd at phd.russ.ru
Thu Nov 25 07:01:47 EST 1999


On Wed, 24 Nov 1999, James Logajan wrote:
> def ifexp(cond, trueVal, falseVal):
>    if cond:
>       return trueVal
>    else:
>       return falseVal
> 
> print "You scored %s point%s" % (score, ifexp(score == 1, "", "s"))

   The problem with this solution is that python will calculate both
expressions (trueVal, falseVal) even if "cond" is false - what is VERY
undesireable in most situations. What if I just cannot calculate falseVal
if "cond" is false?

Oleg.
---- 
    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