# python: sum=0 and sum += variable



## kalibcrone (Mar 3, 2011)

i mostly understand these programs and i understand that to pull each sum of the loop i need to use this sum=0 and sum += veriable in the program, but i would like to know what this means. I'm kinda slow so help me out here.

ex program.

sum=0
for x in range (100,201):
sum += x
print "The sum of all consecutive integers between 100 and 200 =", sum


----------



## Special2God (Oct 5, 2009)

Basically

```
sum += x
```
 is equivalent to

```
sum = sum + x
```
The += is just a short hand version of saying "add the variable on the right to the variable on the left". 
Most Humans think about math statements in terms of "sum + x" or "some * x" or some other operation, but a computer needs to know what to do with "sum + x" so programers have to write "sum = sum + x". 
The first programers that designed modern programing languages such as Python and JavaScript, adopted the += short hand so they did not have to type the name of the variable twice. 
A loop that uses += as in your example would look something like this in memory: 

```
0,
100, 
201, 
303, 
406, 
etc as the growing loop variable is added to the sum variable over and over
```


----------

