You can try using array module to indicate the type of your array:
import array a = array.array('i') # Define an integer array.
Then you can add the elements you want to the array. I'm not sure if you can predetermine the size your array should have. If you need an array of ten integer elements, each element of which is zero, you can do:
a = array.array('i', [0]*10)
As described in the documentation, 'i' forces the elements of the array to be integer. Python 2.6 will throw DeprecationWarning if you try to insert a float into an array of integers, but will distinguish a float as an int:
>>> a[0]=3.14159 >>> a >>> array('i', [3, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Alternatively, you can use the numpy package, which allows you to determine both the size and type of the array.
import numpy as np a = np.empty(10, dtype=int)
np.empty just reserves some memory space for the array, it does not initialize it. If you need an array of 0, you can do:
a[:] = 0
or directly use the np.zeros function:
a = np.zeros(10, dtype=int)
In this case, inserting a float into an array of integers will silently convert the float to integer.
Note the difference between numpy and array : once you define an array in numpy , you cannot resize it without having to create an array. In this sense, it satisfies your requirement "10 and only 10 integers." On the contrary, the object array.array can be considered as a list with a fixed type of element: the array is dynamic, you can increase its size.