<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Why are some methods/functions named in this way in python? __len__<br><br>underscoreunderscoreNAMEunderscoreunderscore<br><br>Is there any speciality of naming such methods?<br><br>--- On <b>Sun, 6/24/12, Ian Kelly <i><ian.g.kelly@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Ian Kelly <ian.g.kelly@gmail.com><br>Subject: Re: How can i call array_length to get the length of array object?<br>To: "gmspro" <gmspro@yahoo.com><br>Cc: "python-list" <python-list@python.org><br>Date: Sunday, June 24, 2012, 12:34 AM<br><br><div class="plainMail">On Sat, Jun 23, 2012 at 8:23 PM, gmspro <<a ymailto="mailto:gmspro@yahoo.com" href="/mc/compose?to=gmspro@yahoo.com">gmspro@yahoo.com</a>> wrote:<br>> I'm trying to call this function, <a
 href="http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657" target="_blank">http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657</a><br>><br>> Is that possible to call that function?<br>><br>> I know it's possible to do:<br>> >>>len(arr)<br><br>You call it just like that.  array_length is the C implementation of<br>__len__ for arrays.<br><br>> Doesn't it call this :<br>> <a href="http://hg.python.org/cpython/file/c0eab397f098/Python/bltinmodule.c#l1283" target="_blank">http://hg.python.org/cpython/file/c0eab397f098/Python/bltinmodule.c#l1283</a><br>> instead of this:<br>> <a href="http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657" target="_blank">http://hg.python.org/cpython/file/3b7230997425/Modules/arraymodule.c#l657</a><br><br>Yes, and builtin_len calls PyObject_Size, which in turn calls the<br>object's sq_length method, which is defined to be
 array_length for<br>arrays.<br></div></blockquote></td></tr></table>