What is the array typecode function in Python?
Overview
An array is a collection of multiple items, elements, or values of the same datatype in a single variable.
The typecode() function is used to return the typecode character used to create the array. Typecodes are used for defining arrays in Python. The table below has some of the typecodes in Python.
| Type code | C type | Python type | Minimum size in bytes |
|---|---|---|---|
'b' |
signed char | int | 1 |
'B' |
unsigned char | int | 1 |
'i' |
signed int | int | 2 |
'I' |
unsigned int | int | 2 |
'f' |
float | float | 4 |
'b' |
double | float | 8 |
Parameter value
The typecode() function takes no parameter value.
Return value
The typecode() function returns the typecode character used to create a given array.
Example
# importing the array moduleimport array as arr# creating an integer data type arrayx = arr.array('i', [1,2,3,4,5,6,7])# using the typecode funtion to ccheck for the array's typecodeprint(x.typecode)
From the output of the code above, the i simply means that the array we created is an integer type.