How to create a fix size list in python?

后端 未结 9 1840
不思量自难忘°
不思量自难忘° 2020-12-04 20:53

In C++, I can create a array like...

int* a = new int[10];

in python,I just know that I can declare a list,than append some items,or like..

9条回答
  •  青春惊慌失措
    2020-12-04 21:40

    Python has nothing built-in to support this. Do you really need to optimize it so much as I don't think that appending will add that much overhead.

    However, you can do something like l = [None] * 1000.

    Alternatively, you could use a generator.

提交回复
热议问题