May 19, 2025
append() to add elements and index() to find elements.array module: import arrayarray.array(typecode, [elements])
typecode specifies the data type of the array.int, float, unicode.b for signed integers (1 byte).B for unsigned integers (1 byte).i for regular integers (2 bytes).f for floats (4 bytes).d for double precision floats (8 bytes).u for Unicode characters (2 bytes).vals = array.array('i', [5, 9, 8, 4, 2])typecode is 'i'.vals.reverse()range(): for i in range(len(vals)): print(vals[i])for val in vals: print(val)new_array = array.array(vals.typecode, (a*a for a in vals))
i = 0
while i < len(new_array):
print(new_array[i])
i += 1