mardi 5 janvier 2021

Different evaluation results of python if else expresion

The following two expressions use if...else...

I can understand the c2 result.

But I wonder why c1 gets different result.

a =10
c1 = 10 + a if a >20 else -a
c2 = 10 + (a if a >20 else -a)
print(c1,c2)

Output: -10 0

Aucun commentaire:

Enregistrer un commentaire