Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How can i call array_length to get the length of array object?

Reply
Thread Tools

Re: How can i call array_length to get the length of array object?

 
 
Stefan Behnel
Guest
Posts: n/a
 
      06-24-2012
gmspro, 24.06.2012 10:01:
> Why are some methods/functions named in this way in python? __len__
>
> underscoreunderscoreNAMEunderscoreunderscore
>
> Is there any speciality of naming such methods?


Yes. Look up "special methods" in the documentation.

You may have noticed the correspondence between len() and __len__(). That
is Python's way of allowing you to implement this kind of generic
functionality (sometimes referred to as a protocol).

You also asked why len() is a function instead of a method. Don't you find
it much easier to use one function for everything than to look up and
sometimes even learn one method for each kind of object you are dealing
with? Python prefers simplicity here. You want the length? Use len().

Stefan

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: How can i call array_length to get the length of array object? Mark Lawrence Python 2 06-25-2012 08:20 PM
Re: How can i call array_length to get the length of array object? Antoon Pardon Python 0 06-25-2012 01:48 PM
Re: How can i call array_length to get the length of array object? Ian Kelly Python 0 06-24-2012 05:34 AM
Re: How can i call array_length to get the length of array object? Ignacio Mondino Python 0 06-24-2012 03:34 AM



Advertisments