Building CPython
Chris Angelico
rosuav at gmail.com
Fri May 15 06:25:22 EDT 2015
On Fri, May 15, 2015 at 8:14 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> (If anything, using an implicit boolean test will be faster than an
> explicit manual test, because it doesn't have to call the len() global.)
Even more so: Some objects may be capable of determining their own
lengths, but can ascertain their own emptiness more quickly. So len(x)
might have to chug chug chug to figure out exactly how many results
there are (imagine a database query or something), where bool(x)
merely has to see whether or not a single one exists (imagine a
database query with "LIMIT 1" tacked on).
ChrisA
More information about the Python-list
mailing list