Duncan Booth wrote:
Gandalf <goldn...@gmail.com> wrote:
other languages ... [have an] if-else operator like...
myVar = checking == 1? 'string': 'other string'
See http://docs.python.org/reference/expressions.html#boolean-operations
...
The expression x if C else y first evaluates C (not x); if C is true, x is
evaluated and its value is returned; otherwise, y is evaluated and its
value is returned.
While we _do_ have the form <expr> if <test> else <expr>, it is
generally agreed that in most cases your code will be more clear
with explicit tests and assignments. Your particular example
is better
if checking:
my_var = 'string'
else:
my_var = 'other string'
remember, vertical space only kills trees if printed.
--Scott David Daniels (who still prints this too frequently).
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list