Easy function, please help.

Rikishi42 skunkworks at rikishi42.net
Wed Feb 9 18:00:48 EST 2011

On 2011-02-09, rantingrick <rantingrick at gmail.com> wrote:
> On Feb 9, 1:08 am, Paul Rudin <paul.nos... at rudin.co.uk> wrote:
>> Nanderson <mandersonrandersonander... at gmail.com> writes:
>> > loop would be infinite. I get what is happening in the function, and I
>> > understand why this would work, but for some reason it's confusing me
>> > as to how it is exiting the loop after a certain number of times. Help
>> > is appreciated, thanks.
>> It works because 0 tests false and because integer division yields
>> integers... eventually you'll get something like 1/10 giving 0.
> It works because of a design flaw in the language! Specifically i am
> referring to treating the integer 0 as False and any other integers as
> True. There is also the empty vs non empty containers that work this
> way besides numeric types.

I would have defined the flaw to be use of '/' for the integer division.

Using 0 as false and any other value as true is hardly unique to python. Lots
of languages have been doing this long before Python even existed.

When in doubt, use brute force.
                -- Ken Thompson

More information about the Python-list mailing list