Logo

Programming-Idioms

Create a new list a (or array, or slice) of size n, where all elements are integers initialized with the value 0.
Implementation
Python

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Python implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
a := make([]int, n)
let a = vec![0; n];
a := nil;
setlength(a, n);
integer, dimension(:), allocatable :: a

allocate(a(n),source = 0)
a = Array.new(n, 0)
a = [0] * n
const a = new Array(n).fill(0);
a = replicate n 0
int[] a = new int[n];
my @a = (0) x $n;
std::vector<int> a(n, 0);
var a = List.filled(n, 0);
import java.util.stream.IntStream;
int[] a = IntStream.generate(() -> 0)
                .limit(n)
                .toArray();
import java.util.*;
List<Integer> a = new ArrayList<Integer>(n);
for (int i =0;i<n;i++){
    a.add(0);
}
var a = new int[n];
(def a (repeatedly n #(identity 0)))