jeudi 2 juillet 2015

Shorten the IF condition for 2 variables (same comparison) python

Following is what I need to do:

if ((a<100 and a>-100) and (b<100 and b>-100)):

#i.e., if both a and b lie in the interval (-100,100)

Was wondering if I can write this in a shorter way.

UPD: Found the following way. Anything shorter than this? (This isn't much short for only 2 variables though)

if all((x > -100 and x < 100) for x in (a,b))

Aucun commentaire:

Enregistrer un commentaire