Raggruppamento di condizioni in Python
Sebbene l'operatore and abbia priorità
su or, spesso è più conveniente usare
le parentesi tonde per raggruppare e mostrare
esplicitamente la priorità delle operazioni:
tst = 3
if (tst > 0 and tst < 5) or (tst > 10 and tst < 20):
print('+++')
else:
print('---')
Nel codice qui sotto, indica la priorità delle operazioni in modo esplicito:
tst = 3
if tst > 5 and tst < 10 or tst == 20:
print('+++')
else:
print('---')
Nel codice qui sotto, indica la priorità delle operazioni in modo esplicito:
tst = 3
if tst > 5 and tst > 0 and tst < 3:
print('+++')
else:
print('---')
Nel codice qui sotto, indica la priorità delle operazioni in modo esplicito:
tst = 3
if tst == 9 and tst > 10 and tst < 20 or tst > 20 and tst < 30:
print('+++')
else:
print('---')