The array is a data structure that holds more than one value at a time.
In the core python list also treated as an array.
In data science, Numpy is used as an array.
Basic python syntax to declare an array in python:
>>> a = arr.array(‘d’, [‘a’, ‘b,’, ‘c’])
The first argument shows an array ‘data-type’ and second is a list of values.
List of array data types
Here we create a simple list of array data types:
I, i, h, H - Use for “int”, size is 3(in bytes
f - Use for “float”, size is 4(in bytes)
d - Use for “float”, size is 4(in bytes)
How to access array element
We can access array element simple way – as per index value
Finding the length of array
Array length can be find using the len() funcition.
>>> x = len(a)
Array with loop
Element of array can be find using the loop, like list or dict.
>>> for x in a:
Adding the element to the array
Element can be added in the array using the "append"
Removing the element from array array
Element can be removed from the array using the pop()
It removes the second element from the array.
We can also remove the element from the array using "remove"
Other array methods which are useful and most important
Here the list of array methods which is most important:
append(), clear(), copy(), count(), extend(), index(), insert(), sort(), reverse(), etc.