Why assignment fails at else part ? I was trying to increment two variables based on a condition in below one line .
>>> a=0
>>> b=0
>>> a+=1 if True else b
>>> a
>>> 1
>>> a if True else b+=1
File "<input>", line 1
SyntaxError: can't assign to conditional expression
>>> a if False else b+=1
File "<input>", line 1
SyntaxError: can't assign to conditional expression
>>> a+=1 if False else b
>>> a
>>> 1
>>> a+=1 if True else b+=1
File "<input>", line 1
a+=1 if True else b+=1
^
SyntaxError: invalid syntax
expression if condition else expression—b+=1is not an expression.a+=1 if False else b. But the accepted answer from @liliscent clarified it.