How to create an integer array in Python?

前端 未结 8 727
旧巷少年郎
旧巷少年郎 2020-12-24 01:11

It should not be so hard. I mean in C,

int a[10]; 

is all you need. How to create an array of all zeros for a random size. I know the zero

8条回答
  •  心在旅途
    2020-12-24 02:07

    If you are not satisfied with lists (because they can contain anything and take up too much memory) you can use efficient array of integers:

    import array
    array.array('i')
    

    See here

    If you need to initialize it,

    a = array.array('i',(0 for i in range(0,10)))
    

提交回复
热议问题