Operator Precedence/Boolean Logic

Antoon Pardon antoon.pardon at rece.vub.ac.be
Thu Jun 23 05:27:36 EDT 2016


Op 23-06-16 om 11:10 schreef Marko Rauhamaa:
> Lawrence D’Oliveiro <lawrencedo99 at gmail.com>:
>
>> On Thursday, June 23, 2016 at 8:17:02 PM UTC+12, Marko Rauhamaa wrote:
>>>     if len(leftover) > 0:    # no, I'd never write this
>>>         ...
>> I regularly write “len(leftover) != 0”. Why not?
> The __len__ method is not guaranteed to execute in O(1). See:
>
>    <URL: https://docs.python.org/3/reference/datamodel.html?highlig
>    ht=__len__#object.__len__>

As far as I can see, neither is the __bool__ method.

-- 
Antoon.



More information about the Python-list mailing list