Jul 23, 2024
append()
: To add values.index()
: To find the index of a particular value.Importing the Array Module:
import array
to access array functionalities.import array as a
for shorthand usage (e.g., a.array()
).from array import *
.Creating an Array:
array(typecode, [values])
import array
vals = array('i', [5, 9, 8, 4, 2])
i
: signed intI
: unsigned intf
: floatd
: double floatu
: Unicode charactersvals[0]
accesses first element.for
loops:
for e in vals:
print(e)
len()
, allowing dynamic ranges.append()
: Adds an element.remove()
: Removes an element.reverse()
: Reverses elements in-place.buffer_info()
: Returns address and size of the array.new_vals = array(vals.typecode, [val for val in vals])
i = 0
while i < len(new_array):
print(new_array[i])
i += 1