len() should always return something

bartc bartc at freeuk.com
Sat Jul 25 01:15:32 CEST 2009


"Dr. Phillip M. Feldman" <pfeldman at verizon.net> wrote in message 
news:mailman.3644.1248417347.8015.python-list at python.org...
>
> Some aspects of the Python design are remarkably clever, while others 
> leave
> me perplexed. Here's an example of the latter: Why does len() give an 
> error
> when applied to an int or float? len() should always return something; in
> particular, when applied to a scalar, it should return a value of 1.

So you want len() to treat 123 as though it could potentially be a list 
containing a single element?

In that case there could be an ambiguity here:

print len([10,20,30])

Should it print 3 (the elements in [10,20,30]), or 1 (treating [10,20,30] as 
a potential list containing the single element [10,20,30])?

-- 
bartc 




More information about the Python-list mailing list