0

I am a very amateur programmer, and I want to make an array full of 0s, that is the length of a number.

How do I do that?

Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
Itamar
  • 11
  • 3
    `[0] * num` - but note that for array of arrays (or other mutable objects) you'd need `[[] for _ in range(num)]` – Amadan Oct 19 '18 at 10:53
  • 9
    Possible duplicate of [Create an empty list in python with certain size](https://stackoverflow.com/questions/10712002/create-an-empty-list-in-python-with-certain-size) – awesoon Oct 19 '18 at 10:57

3 Answers3

0

here is how you can do that

i=7; arr=[0]*i;

0

Create a list and use a for loop to fill it with 0's.

my_list = []

for _ in range(n):
  my_list.append(0)
0
In [1]: a = [0] * 7     # if length is 7

In [2]: a
Out[2]: [0, 0, 0, 0, 0, 0, 0]
Vishvajit Pathak
  • 3,351
  • 1
  • 21
  • 16