On Sun, Jul 27, 2008 at 10:17 AM, DaveM <[EMAIL PROTECTED]> wrote:

> On Sun, 27 Jul 2008 05:24:36 -0700 (PDT), alex23 <[EMAIL PROTECTED]>
> wrote:
>
> >On Jul 27, 10:13 pm, ssecorp <[EMAIL PROTECTED]> wrote:
> >> I have seen somewhere that you can write something like:
>
> >> x*x if x>10
> >> but exactly that doesn't work and I can't get any variation to work.
>
> >It's called a ternary operator. The format is:
> ><label> = <true-value> if <condition> else <false-value>
>
> I've seen the PERL saying/motto/boast, "There's more than one way to do it"
> derided on more than one occasion on this group so what's the reason for
> this additional way to put an if else statement on one line? Are "and" and
> "or" constructions to produce the same effect not supported for this use?
>

In fact the PEP for this construct states:

The motivating use case was the prevalance of error-prone attempts
to achieve the same effect using "and" and "or".

See: http://www.python.org/dev/peps/pep-0308/

Karen
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to