user299648 user299648 - 1 year ago 103
Python Question

How do I get a empty array of any size I want in python?

I basically want a python equivalent of this in C

int a[x];

but in python I declare an array like

a = []

but the problem is I want to assign random slots with values like

a[4] = 1

but I can't do that with python, since the array is empty

Answer Source

If by "array" you actually mean a Python list, you can use

a = [0] * 10


a = [None] * 10
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download