+ 1

In Python 3 this symbols i don't understand (%=, /=, //=, -=, +=, *=, **=) please give me examples and explain also.

%=, /=, //=, -=, +=, *=, **=

7th Jun 2019, 11:27 AM
Rupak Barman
Rupak Barman - avatar
3 odpowiedzi
+ 10
There is actually a difference between a = a+ b and a += b. If you are doing this on a mutable object (like a list) the first one creates a new object and the second one mutates the original one. Usually this doesn't matter but if you don't know about it, it can be a bug that's very hard to find.
7th Jun 2019, 12:43 PM
Thoq!
Thoq! - avatar
+ 4
a %= b is the same as a = a % b It works the same way for all of them
7th Jun 2019, 11:39 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar