In python how can I set multiple values of a list to zero simultaneously?

前端 未结 5 1148
南旧
南旧 2021-02-04 02:10

Conceptually, I want to do:

arr[20:] = 0

where arr is a list. How can I do this?

5条回答
  •  迷失自我
    2021-02-04 03:03

    You can make a function that you will pass the array to that will zero out the array. I haven't used Python in a while, so I won't attempt to show you the Python code. In that function you could use a for or while loop to iterate through each value and setting each one equal to zero.

提交回复
热议问题