Can the += operator be used to add more than one value at a time?


#1

Question

In Python, can the += operator be used to add more than one value at a time?

Answer

Yes, the += operator allows adding more than just a single value at a time. Anything on the right-hand side of the += will be evaluated, and then it will be added to the variable which is then updated to that new value.

Example code

# Plus Equals with a single value:
miles = 80
miles += 20 # miles is now 100

# Plus Equals with more than one value:
snow_level = 10
snow_level += 20 + 10 + 40 # snow_level is now 80