FW: Unexpexted behaviot of python operators on list
breamoreboy at yahoo.co.uk
Tue Nov 25 13:20:26 CET 2014
On 25/11/2014 11:40, Steven D'Aprano wrote:
> PANDEY2 Archana (MORPHO) wrote:
>> I hereby would like to share the problem I have found regarding python
>> list implementation:-
>> As per python documentation python list is mutable data object.
>> That problem I found with the list is that is behaves differently when we
>> use '+=' and '+' '=' operators separately. For example-
>> a=a+1 and a +=1 both behave in same way for all data types except python
> `a += b` is only *approximately* the same as `a = a+b`. The documentation
> An augmented assignment expression like x += 1 can be rewritten as x = x + 1
> to achieve a similar, but not exactly equal effect. In the augmented
> version, x is only evaluated once. Also, when possible, the actual
> operation is performed in-place, meaning that rather than creating a new
> object and assigning that to the target, the old object is modified
>> Please find the attached module and execute it on windows python32, See
>> the difference in output.
> I cannot see the attached module. Did you forget to attach it, or did your
> mail server delete it?
I know that you can explain it better than I can :)
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
More information about the Python-list