something like "if" that returns a value?

holger krekel pyth at devel.trillke.net
Mon Nov 11 11:13:31 EST 2002


Paul Rudin wrote:
> >>>>> "hk" == holger krekel <pyth at devel.trillke.net> writes:
>  >> - there's a degree of obfuscation here, the code is less
>  >> comprehensible than something like: if x then y else z.
> 
>  hk> IMO it's not overly hard to get used to it. It certainly isn't as
>  hk> evident (as has the aforementioned pitfall) as in some other
>  hk> languages.  Funny enough, i don't need this ternary operation
>  hk> often.
> 
>  hk> And if one the expressions is more complex i use a proper
>  hk> if-clause.
> 
> I guess these things depend on what you're used to - I now program
> mostly in lisp; I used to program mostly in c++; I'm very used to
> using such a construct. Using an if-then-else type construct without a
> return value makes some code rather inelegant, it seems to me. But no
> doubt one can get used to it.

yes.  But i also said that with python i don't need this ternary
operator often (usually in cases where applying the 'x and y or z' 
is no problem).  It happend to me that instead of using a ternary
operator i cut simplify, shorten *and* enhance my program by not 
doing so.  Is there an obvious killer use case?  IOW can you
state a problem where the use of a ternary operator comes in
really handy?  Sorry if this sounds dumb to you but i am interested.

regards,

    holger




More information about the Python-list mailing list