mardi 19 novembre 2019

python parentheses priority in if-statement. Difference between (1 or 2) and (2 or 1)

a = 1

if a == (1 or 2): print(1)

if a == (2 or 1): print(2)

if a == 1 or 2: print(3)

if a == 2 or 1: print(4)

python only prints 1,3,4

what is the difference between "(1 or 2)" and "1 or 2"

Aucun commentaire:

Enregistrer un commentaire