what is foo.__add__ in python means?
<p>i ususally see when we create class in python we use  <code>__init__(self)</code> , I just come across this code :</p>

<pre><code>&gt;&gt;&gt; foo = 10
&gt;&gt;&gt; print(foo.__add__)
&lt;method-wrapper '__add__' of int object at 0x8502c0&gt;
</code></pre>

<p>so  i have two doubts:</p>

<p>can someone explain in deep what it means when someone write something in <code>__something__</code> (i know its private class but what it do when we write like <code>hello.__something__)</code> ? instance ?
Second doubt is why we use self <code>(__init__(self))</code></p>

<p>P.S: if you are going to redirect me at any other question which explain what is <code>__something__</code> then still i request you please answer what <code>foo.__add__</code> means ?</p>

<p>When Python tries to evaluate <code>x + y</code>, it first attempts to call <code>x.__add__(y)</code>. If this fails then it falls back to <code>y.__radd__(x)</code>. In short, <code>__add__()</code> defines the behavior of <code>+</code> operator.</p>

<p>For example, <code>1 + 2</code> results in 3, whereas <code>[3] + [4]</code> results in <code>[3, 4]</code>. Below is the sample example:</p>

<pre><code>class Test(object):
    def __init__(self, p):
        self.p = p

    def __add__(self, value):
        return '{} - {}'.format(self.p, value)

test = Test('hello')
test + 'world'
# returns: 'hello - world'
</code></pre>

python python-2.7 python-3.x