something like "if" that returns a value?
holger krekel
pyth at devel.trillke.net
Mon Nov 11 06:28:34 EST 2002
Paul Rudin wrote:
>
> I'm having a little play with python, just to try it out; and one
> thing that I find I miss from other languages is something like lisp's
> if:
>
> (if x y z)
>
> which returns y if x is true and z otherwise.
>
> I realise that I can define a function that does this for me; but is
> there a succinct way of expressing this in the base language?
for me
x and y or z
basically does what you want. But you *need* to be sure that 'y'
is true. some people don't like this 'abuse' but many use
it on a regular basis (without big problems i'd say).
regards,
holger
More information about the Python-list
mailing list