4 comments

[ 2.9 ms ] story [ 19.7 ms ] thread
For those wondering what the hell truth() is, I think they're talking about this phenomenon:

  python -m timeit "if bool(1): x = 1"
  1000000 loops, best of 3: 0.187 usec per loop

  python -m timeit "if 1: x = 1"
  10000000 loops, best of 3: 0.0266 usec per loop
truth() is a function defined in the operator module which does kind of the same thing as bool().
This article doesn't actually answer the question posed by the title, FYI.
Uncommon to see such a linkbaitish title for a programming post. The reason truth() (from operator) is faster than bool() is that

* bool() takes one optional and named argument, and

* truth() takes one argument.