Defending the ternary operator
David Eppstein
eppstein at ics.uci.edu
Sat Feb 8 12:32:03 EST 2003
In article <yu99k7gaagav.fsf at europa.research.att.com>,
Andrew Koenig <ark at research.att.com> wrote:
> EXAMPLE 6:
>
> p = (s == NULL)? str: s;
>
> This example sets a default value to substitute for s in case s is NULL.
> The likely rewrite:
>
> if (s == NULL)
> p = str;
> else
> p = s;
What's wrong with using s || str in this example?
--
David Eppstein UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list
mailing list