Python += | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
2nd Mar 2022, 6:13 AM
Sl1ner
2 Answers
+ 4
+= is known as assignment operator in python. i += 1 is treated as i = i +1
2nd Mar 2022, 6:16 AM
Simba
Simba - avatar
+ 1
For immutable types like the int in your code, i = 0 i += 1 would be the same as i = i + 1 For a mutable type like a list, it would work similarly to the lists append() method. a = [1,2,3] b = [4,5,6] a += b a is now [1,2,3,4,5,6] += adds/appends/concatenates the R-value to the L-value and then assigns the result back to the L-value.
2nd Mar 2022, 6:21 AM
ChaoticDawg
ChaoticDawg - avatar