In [12]: a =+ 5
In [13]: a
Out[13]: 5
In [14]: a =+ -5
In [15]: a
Out[15]: -5
In [16]: a =+ 5.8
In [17]: a
Out[17]: 5.7999999999999998
In [18]: a =+ -5.8
In [19]: a
Out[19]: -5.7999999999999998
But if you use with any other type it will raise an error:
In [40]: a =+ 'test'
---------------------------------------------------------------------------
exceptions.TypeError Traceback (most recent call last)
/home/murtog/<console>
TypeError: bad operand type for unary +
In [41]: a =+ []
---------------------------------------------------------------------------
exceptions.TypeError Traceback (most recent call last)
/home/murtog/<console>
TypeError: bad operand type for unary +
In [42]: a =+ {}
---------------------------------------------------------------------------
exceptions.TypeError Traceback (most recent call last)
/home/murtog/<console>
TypeError: bad operand type for unary +
Ok ? i think that you wanted the: __add__ method. this other sample may help you:
In [66]: a = 5
In [67]: a.__add__(3)
Out[67]: 8
In [68]: a
Out[68]: 5
In [69]: a = a.__add__(3)
In [70]: a
Out[70]: 8
I hope this help you. I havent found the __iadd__ operator...
Sent from the Python - python-list forum at Nabble.com:
Re: special operator =+
-- http://mail.python.org/mailman/listinfo/python-list