K
K
Kollapser2020-09-02 15:20:12
Python
Kollapser, 2020-09-02 15:20:12

Exclude in the condition or assign again each time?

Option 1
if (abs(self.speedx) < 0.4) and self.speedx != 0:
self.speedx = 0

Option 2
if abs(self.speedx) < 0.4:
self.speedx = 0

Which option is better and why? Or is there no fundamental difference?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2020-09-02
@Kollapser

Savings on matches ...
But if you want, then look at what is more likely.
If in your data the situation speedx == 0 is much more common than getting into the range 0+ .. 0.4 - then option 1 probably makes some sense ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question