ibie808 ibie808 - 5 months ago 16
Python Question

Difference between "=" and "+=" on python?

What is the Difference between "=" and "+=" on python? (Without speech marks)
I've been experimenting, and I haven't found the difference...
I'm not fluent in python, however - I am on "A Day at the Supermarket" on Codeacademy.
Thanks for all your answers!

Answer

In python, the phrase x=4 will assign the value of 4 to x. However, the phrase x+=4 will increment 4 to the current value of x. For example:

x = 3
print x #will print 3
x += 2
print x #will print 5
Comments