-2

Possible Duplicate:
What does += mean in Python?

I have a def function looks like:

def s(xs, n, m):
    t = []
    while n < m:
        t.append(xs[n])
        n += 2
    return t

I understand the above code by t.append(xs[n]), but have no idea what n += 2 means here.

Any help will be appreciated. Thanks

Community
  • 1
  • 1
JuM
  • 447
  • 1
  • 7
  • 10
  • It's equivalent to n = n + 2; specifically, the function returns an array with every other element of the inputted array starting at the initial index n and going until index m. – Merbs Oct 23 '12 at 02:50
  • 3
    Read the docs. http://docs.python.org/reference/simple_stmts.html#augmented-assignment-statements – Matt Ball Oct 23 '12 at 02:52

1 Answers1

2

It adds 2 to n. And I need 30 characters for an answer.

Fred Larson
  • 60,987
  • 18
  • 112
  • 174