3 ms·
But in your proposed solution b would be evaluated twice. So you would have to add a new line, think of a new variable name, and so on. if lower < x.calculat
by hmry 6y ago
But in your proposed solution b would be evaluated twice. So you would have to add a new line, think of a new variable name, and so on.
if lower < x.calculate_weight() < upper:
...
Suddenly turns into
x_weight = x.calculate_weight()
if lower < x_weight and x_weight < upper:
...
- nitroll 6y agoAnd is that so bad? So often i did stuff like that, then finding I actually need the result of x.calculate_weight() inside the condition, or to debug it or log it in some way. Then it has to be extracted anyway.