"Rustom Mody" <[email protected]> wrote in message
news:[email protected]...
On Wednesday, October 22, 2014 5:01:08 PM UTC+5:30, Ned Batchelder wrote:
On 10/22/14 5:05 AM, buscacio wrote:
> Em quarta-feira, 22 de outubro de 2014 06h29min55s UTC-2, ast
> escreveu:
>> Hello
>> Is there in Python something like:
>> j = (j >= 10) ? 3 : j+1;
>> as in C language ?
>> thx
> without not:
> j = [j+1, 3][j>=10]
> with not:
> j = [3, j+1][not (j>=10)]
Why on earth would you recommend this outdated hack, when there's a true
conditional operator?
To learn a bit about the interchangeability of control and data
structures?
[Just playing devil's advocate]
But it doesn't do the same thing.
Comparing:
x = cond ? f() : g(); # C version
with
x = [f(), g()] [cond]
the latter evaluates both f() and g() instead of just one. Apart from being
inefficient, it can have unintended side-effects.
--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list