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>You can also use <a href="https://docs.python.org/3/library/operator.html" rel="nofollow"><code>operator</code></a> package</p>

<pre><code>import operator


class Solution(object):
    def getSum(self, a, b):
        return operator.add(a, b)
</code></pre>

<p>And if you want to hassle with binary bitwise operations. Here is first method:</p>

<pre><code>def complex_add_1(x, y):
    while y != 0:
        b = x &amp; y
        x = x ^ y
        y = b &lt;&lt; 1
    return x
</code></pre>

<p>And here is the another one with recursion:</p>

<pre><code>def complex_add_2(x, y):
    if y == 0:
        return x
    else:
        return complex_add_2(x ^ y, (x &amp; y) &lt;&lt; 1)
</code></pre>

<p><strong>Edit</strong>: methods with bitwise operations are working only in Python 3</p>

python