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

Discussion in 'Python' started by Stefan Behnel, Jun 24, 2012.

  1. 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
    Stefan Behnel, Jun 24, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mitchua
    Replies:
    5
    Views:
    2,715
    Eric J. Roode
    Jul 17, 2003
  2. Ignacio Mondino
    Replies:
    0
    Views:
    279
    Ignacio Mondino
    Jun 24, 2012
  3. Ian Kelly
    Replies:
    0
    Views:
    220
    Ian Kelly
    Jun 24, 2012
  4. Mark Lawrence
    Replies:
    2
    Views:
    244
    Terry Reedy
    Jun 25, 2012
  5. Antoon Pardon
    Replies:
    0
    Views:
    228
    Antoon Pardon
    Jun 25, 2012
Loading...

Share This Page