Check if a given value is out of certain range

Jussi Piitulainen harvesting at makes.email.invalid
Mon Oct 5 06:08:33 EDT 2015


Michiel Overtoom writes:
> Why not use a function?
>>> if outside(x, 0, 10):
> print("x has wrong value")
> else:
> print("x has good value")
>>> where 'outside' is defined as:
>> def outside(value, lowerbound, upperbound):
> return value < lowerbound or value > upperbound 

Wouldn't that be more readable as:?
 def outside(value, lowerbound, upperbound):
 return not (lowerbound <= value <= upperbound)
Just wondering ...


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /