ternary operator
Andrew Koenig
ark at research.att.com
Fri Feb 7 09:15:50 EST 2003
David> Life gets "interesting" if there is a side effect in the
David> unevaluated portion of the conditional:
David> if a > b and c < d():
David> print e
David> d() might never get called. Not good if d() does something you
David> depend on.
On the other hand, short-circuiting greatly simplifies the
implementation of a number of commonly used algorithms:
i = 0
while i < len(x) and x[i] != y:
i += 1
Try writing this loop without short-circuiting and see how much more
complicated it becomes.
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list