Initialising an array of fixed size in python

kbb picture kbb · May 26, 2011 · Viewed 582.9k times · Source

I would like to know how i can initialise an array(or list), yet to be populated with values, to have a defined size.

for example in C:

int x[5]; /* declared without adding elements*/

How do i do that in python?

Thanks.

Answer

samplebias picture samplebias · May 26, 2011

You can use:

>>> lst = [None] * 5
>>> lst
[None, None, None, None, None]