3 ms·
> (a++ if a==b else b++) + 1 Please rewrite this as if a == b: a += 1 else: b += 1 and don't leave the other developers (or yourself two months f
by pmontra 4y ago
> (a++ if a==b else b++) + 1
Please rewrite this as
if a == b:
a += 1
else:
b += 1
and don't leave the other developers (or yourself two months from now) scratching their head about what that code does. You have more important things to do than trying to understand your code again and again.
Furthermore, does that + 1 at the end run before or after the ++?
> (a++ if a==b else b++) + 1
I had to try it out (with a syntax that can run)
>>> a = 1
>>> b = 2
>>> (a+1 if a == b else b+1) + 1
4 # the expression evaluates to 4, wtf!
>>> a
1
>>> b
2
But this is not a += 1 which is syntax error and the point of your post.