A = X > Y ? X : Y

Michal Wallace sabren at manifestation.com
Wed Feb 9 12:09:42 EST 2000


Skip Montanaro wrote in message
<14497.40204.132370.427503 at beluga.mojam.com>...
>    Michal> I know there's been a couple replies to this... but why not do
>    Michal> something like VB's (or at least VBA's - not sure if VB proper
>    Michal> has it) "immediate If" function?
>
>    Michal> def iif( condition, first, second ):
> ...
>    Michal> then it's:
>
>    Michal> a = iif( a > y, x, y )
>
>Wrong semantics.  Both x and y will be evaulated before the function call
>regardless of the value of the condition.


Oh. I see the difference now... I think VB does the same thing.
But that's actually a good thing!! Python encourages you to use
"if" when you really want to change values.. "iif" is really more for
things like print statements, not for assigning values..

print "You are really", iif(age<100, "young", "old")

Print statements with side effects scare me... ;)

-michal
http://www.sabren.com/






More information about the Python-list mailing list