If you really want a C style array
import array a = array.array('i', x * [0]) a[3] = 5 try: [5] = 'a' except TypeError: print('integers only allowed')
Note that in python there is no concept of an uninitialized variable. A variable is a name that is associated with a value, so this value must have something. In the above example, the array is initialized to zeros.
However, this is rare in python, unless you need it for low level things. In most cases, it is better to use an empty list or an empty numpy array, as other answers suggest.
blue_note Jun 06 '19 at 2:06 p.m. 2019-06-06 14:06
source share