Sum of Two Integers without using '+' operator in python 2 or 3
<pre><code>class Solution(object):
    def getSum(self, a, b):
        if (a == 0):
            return b
        if (b == 0):
            return a;
        while(b != 0):
            _a = a ^ b
            _b = (a &amp; b) &lt;&lt; 1
            a = _a
            b = _b
        return a
</code></pre>

<p>But when one of a, b &lt; 0 or both, how the script should be like?</p>

<p><code>+</code> operator internally makes a call to <code>__add__()</code>. So, you may directly call <code>a.__add__(b)</code> to get sum. Below is the modified code:</p>

<pre><code>&gt;&gt;&gt; class Solution(object):
...     def getSum(self, a, b):
...         return a.__add__(b)
... 
&gt;&gt;&gt; s = Solution()
&gt;&gt;&gt; s.getSum(1, 2)
3
</code></pre>

<p><strong>OR</strong>, you may use <a href="https://docs.python.org/2/library/operator.html#operator.add" rel="nofollow"><code>operator.add(a, b)</code></a> as:</p>

<pre><code>&gt;&gt;&gt; import operator
&gt;&gt;&gt; operator.add(1, 2)
3
</code></pre>

python