How to create an integer array in Python?

前端 未结 8 708
旧巷少年郎
旧巷少年郎 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)))
    
    0 讨论(0)
  • 2020-12-24 02:07
    >>> a = [0] * 10
    >>> a
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    
    0 讨论(0)
提交回复
热议问题