A = X > Y ? X : Y

Bob Alexander bobalex at home.com
Wed Feb 9 14:17:22 EST 2000

The only true equivalent to this C/C++/Java/<name your c-like syntax
language> code in Python is:

if X > Y:
  temp = Y
  temp = X
A = temp

This evaluates only one of its selected expressions, and evaluates A only
once. Its only fault is its lack of "hygiene" in that it puts a variable
"temp" into the namespace.

It can't be encapsulated into something that looks like a function call
since Python doesn't support macros. Functions always evaluate all of their
arguments before invoking function code, so there is no way to evaluate only
one of the selected expressions.

-- Bob

More information about the Python-list mailing list