len() should always return something

Hendrik van Rooyen hendrik at microcorp.co.za
Sat Jul 25 03:50:30 EDT 2009


On Friday 24 July 2009 16:45:40 Mark Dickinson wrote:

> On Jul 24, 3:11 pm, "Rhodri James" <rho... at wildebst.demon.co.uk>
>
> wrote:
> > Which doesn't make your point less valid.  In fact I'd go so
> > far as to argue that what len() gives you is the number of
> > items in a container, so len(7) should return 0.
>
> Nah.  7 contains three bits, so len(7) should *clearly* return 3.

Almost right - however the first seven that you typed was a string
seven and not an int - so the hex is 37 and that takes at least
six bits...

:-)

Now if only someone can figure out a reason why it should
return seven, then it would be perfect!

- Hendrik



More information about the Python-list mailing list