On Mon, May 31, 2010 at 3:41 AM, Xavier Ho <cont...@xavierho.com> wrote:
> On 31 May 2010 20:19, Payal <payal-pyt...@scriptkitchen.com> wrote:
<snip>
>> When I type help(something) e.g. help(list), I see many methods like,
>> __methodname__(). Are these something special?
>
> They're very special. You can think of them as "Python internal functions",
> and are called internally by other functions.
>
>>
>> How do I use them and why
>> put "__" around them?
>
> You call them as if they were any other function. 99% of the time though,
> you don't need to call them, as there are better, cleaner ways.


To be a bit more specific, double-underscore methods are called
internally by Python to implement various operators.
For example, `a + b` is usually equivalent to `a.__add__(b)`, and
`len(a)` calls `a.__len__()` internally.
For more info, see
http://docs.python.org/reference/datamodel.html#special-method-names

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to