why len(list) instead of list.len() ?

Emile van Sebille emile at fenx.com
Tue Jun 18 10:03:52 EDT 2002


"Markus Jais" <mjais at web.de> wrote in message
news:EhBP8.1$Qn1.1124 at news.ecrc.de...
> hello
>
> I way wondering why one has to write
>
> list = [2, 3, 5]
> print len(list)
>
> instead of list.len()
>
> in Ruby I can write
>
> array = [2, 3, 4]
> puts array.length()
>
>

Because a two-line wrapper goes a long way?

Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class myList(list):
...     len = list.__len__
...
>>> l = myList([1,2,3,4])
>>> l
[1, 2, 3, 4]
>>> l.len()
4
>>> l.extend([5,6,7])
>>> l.len()
7



--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list