Rant (was Re: x*x if x>10

Karen Tracey kmtracey at gmail.com
Sun Jul 27 10:44:43 EDT 2008


On Sun, Jul 27, 2008 at 10:17 AM, DaveM <asma61 at dsl.pipex.com> wrote:

> On Sun, 27 Jul 2008 05:24:36 -0700 (PDT), alex23 <wuwei23 at gmail.com>
> wrote:
>
> >On Jul 27, 10:13 pm, ssecorp <circularf... at gmail.com> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080727/65060814/attachment-0001.html>


More information about the Python-list mailing list