Skip to main content
2 of 2
added 320 characters in body
SuperBiasedMan
  • 13.1k
  • 5
  • 36
  • 62

You don't need to type this out fully:

total_sum = total_sum+i

Python has a += operator, basically shorthand for what you have above. Take what's on the left of the operator and add the result of what's on the right.

total_sum += i

Also when in Python2.7 it's recommended you use for i in xrange(1000). range will immediately create a full list of numbers it stores in memory, while xrange is a generator that produces each number as it's needed. The performance difference is helpful for large ranges but it's generally a good habit to keep.

SuperBiasedMan
  • 13.1k
  • 5
  • 36
  • 62