For review: PEP 308 - If-then-else expression

Janto Dreijer janto_d at hotmail.com
Sun Feb 9 08:11:22 EST 2003


David Eppstein <eppstein at ics.uci.edu> wrote in message news:<eppstein-05AB4D.15243208022003 at news.service.uci.edu>...
> In article <f9068f8e.0302081508.8615a97 at posting.google.com>,
>  janto_d at hotmail.com (Janto Dreijer) wrote:
> 
> > I find it difficult to imagine a situation where the short-circuit
> > behavior actually matters. Theoretically an ifelse function doesn't do
> > the same thing, but practically it does: Whenever I've used ternary
> > ops there weren't any side effects to evaluating both arguments.
> > Neither any performance ones.
> > 
> > Can someone give me a real world example of its usefulness?
> 
> There have already been a couple of examples posted in this thread, 
> where one side contains an array reference that could give an array out 
> of bounds if the condition is not met.

I can't find the specific example you're referring to. I must have
missed one of the 500+ posts :-)

An out-of-bounds error in python?
The only equivalent I can think of is a dict lookup for a non-existent
key. And that would be done better with ``x = dict().get(key,
default)``.




More information about the Python-list mailing list