Alternate between add and subtract on a list of numbers
<p>How to get the sum of the series 1-2+3-4+5-6+7-8+9-10 in python? </p>

<p>I know how to get the sum of numbers from 1 to a particular number by using while loop in this way:</p>

<pre><code>i = 1
sum = 0
while i&lt;= 10:
    sum = sum + i
    i = i + 1
print(sum)
</code></pre>

<p>It can also be seen as <code>sum of odd</code> minus <code>sum of even</code></p>

<pre><code>sum(range(1, 11, 2)) - sum(range(2, 11, 2))
</code></pre>

python list