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>This was kinda fun :) I'm not sure if this is what you're after, but these all should work so long as you're using integers</p>

<pre class="lang-python prettyprint-override"><code>def subtract(a, b):
    if a &lt; 0:
        return negative(add(negative(a), b))
    if b &lt; 0:
        return add(a, negative(b))
    if a &lt; b:
        return negative(subtract(b, a))
    if b == 0:
        return a
    return subtract(a^b, (~a &amp; b) &lt;&lt; 1)

def negative(a):
    if a == 0: return 0
    a = ~a
    b = 1
    while b &gt; 0:
        a, b = a^b, (a&amp;b) &lt;&lt; 1
    return a

def add(a, b):
    if a &lt; 0:
        return negative(subtract(negative(a), b))
    if b &lt; 0:
        return subtract(a, negative(b))
    if b == 0:
        return a
    return add(a^b, (a &amp; b) &lt;&lt; 1)

def multiply(a, b):
    if a == 0 or b == 0:
        return 0
    if b &lt; 0:
        a = negative(a)
        b = negative(b)
    A = 0
    while b &gt; 0:
        A = add(A, a)
        b = subtract(b, 1)
    return A

def div(a, b):
    if b == 0:
        raise ZeroDivisionError
    if a == 0:
        return 0
    if b &lt; 0:
        a = negative(a)
        b = negative(b)
    A = 0
    if a &lt; 0:
        while a &lt; 0:
            a = add(a, b)
            A = subtract(A, 1)
    else:
        while b &lt; a :
            a = subtract(a, b)
            A = add(A, 1)
    return A

def mod(a, b):
    return subtract(a, multiply(div(a, b),b))
</code></pre>

<p>negation by <a href="https://en.wikipedia.org/wiki/Two%27s_complement" rel="nofollow">two's compliment</a> is used to get a function where a and b are both greater than 0 and the correct operation (addition or subtraction) is selected. further with subtraction, care is taken to not yield a negative result. This is done because the recursive definitions of add and subtract hate crossing 0. Also in this case the recursive add and subtract do the exact same thing as your loop. </p>

python