Python等价于php的foreach($array as $key =>&$value)

有什么相当于这个PHP符号,它改变原始数组(注意引用运算符)?

// increase value of all items by 1
foreach ($array as $k => &$v) {
    $v++;
}

我只知道这样,这不是那么优雅:

for i in range(len(array)):
    array[i] += 1 
你可以使用list comprehension

newArray = [i + 1 for i in array]
翻译自:https://stackoverflow.com/questions/5851753/python-equivalent-of-phps-foreacharray-as-key-value

转载注明原文:Python等价于php的foreach($array as $key =>&$value)