With the help of type codes, we can dynamically create arrays of our own on Python. To recall what arrays are, see this link.
'i'
data type# importing array from array creationsimport array as arr# to create an array of integer datatype ia = arr.array('i', [1, 2, 3, 4, 5, 6, 7 ])# printing the newly created arrayprint('The integer datatype of array is: ', a)# to check for the type of arrayprint("The data type of the array is: ", a.typecode)
array
module in Python.a
of integer type.a
, which we created in line 5.array.typecode
function to check the data type of the array we created.'d'
data type# importing array from array creationsimport array as arr# to create an arry in double float datatype da =arr.array('d', [1.2, 2.5, 6.4, 5.1, 4.5] )# printing the float arrayprint('The float datatype of array is: ', a)# to check for the data type of the arrayprint("The data type of the array is: ", a.typecode)
array
module in Python.a
of float data type.a
, which we created in line 5.array.typecode
function, we check for the data type of the array we created.