Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

People also ask

How do I assign a list of values to zero in Python?

Use the * Operator to Create a List of Zeros in Python. If we multiple a list with a number n using the * operator, then a new list is returned, which is n times the original list. Using this method, we can easily create a list containing zeros of some specified length, as shown below.

How do you assign multiple variables to the same value in Python?

You can assign the same value to multiple variables by using = consecutively. This is useful, for example, when initializing multiple variables to the same value. It is also possible to assign another value into one after assigning the same value.


Conceptually, I want to do:

arr[20:] = 0 

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