Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #24383 > unrolled thread

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

Started byStefan Behnel <stefan_ml@behnel.de>
First post2012-06-24 10:48 +0200
Last post2012-06-24 10:48 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How can i call array_length to get the length of array object? Stefan Behnel <stefan_ml@behnel.de> - 2012-06-24 10:48 +0200

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

FromStefan Behnel <stefan_ml@behnel.de>
Date2012-06-24 10:48 +0200
SubjectRe: How can i call array_length to get the length of array object?
Message-ID<mailman.1446.1340527717.4697.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web