-2
可能重複:
What does += mean in Python?python - 這個def中n + = 2是什麼?
我有一個DEF函數看起來像:
def s(xs, n, m):
t = []
while n < m:
t.append(xs[n])
n += 2
return t
我明白通過t.append上面的代碼(XS [N]) ,但不知道這裏n + = 2是什麼意思。
任何幫助將不勝感激。 謝謝
它相當於n = n + 2;具體來說,該函數返回一個數組,其中包含從輸入數組的所有其他元素開始的索引n,並且一直到索引m。 – Merbs
閱讀文檔。 http://docs.python.org/reference/simple_stmts.html#augmented-assignment-statements –