What is array?
Arrays are data structures consisting of data items of the same type. That is, an array
is a collection of data items stored at contiguous memory locations.
• Arrays are “static” entities, in that they remain the same size once they are
created.
• The idea of array is to store multiple items of the same type together. This makes
it easier to calculate the position of each element by simply adding an offset to a
base value, i.e., the memory location of the first element of the array.
• An integer array called c.
• This array contains 12 elements.
• A program can refer to any element of an array by giving the name of the array
followed by the position number of the element in square brackets ([]).
• The first element in every array is the zeroth element.
• Thus, the first element of array c is referred to as c[ 0 ], the second element of
array c is referred to as c[ 1 ].
• The position number in square brackets is more formally called a subscript (or an
index). A subscript must be an integer or an integer expression.
Arrays can be declared in various ways in different languages.
Python:
from array import *
myarray=array('d', [3.0,8.5,4.7,9.0,20.6])
or
import array as arr
myArray= [Link]('i', [1,1,3,5,2])
Python arrays: Array is a container which can hold a fix number of items/elements of
the same type.
Following are the important terms to understand the concept of Array.
• Element− Each item stored in an array is called an element.
• Index − Each location of an element in an array has a numerical index, which
is used to identify the element
Elements
myArray= [Link]('i', [1,1,3,5,2])
Name Data type Index 2
Following are the important points to be considered.
• Index starts with 0.
• Array length is 5 which means it can store 5 elements.
• Each element can be accessed via its index. For example, we can fetch an
element at index 2 as 3.
Some Basic Operations on array:
• Traverse − Explore/print all the array elements one by one.
• Insertion − Adds an element at the given index.
• Deletion − Deletes an element at the given index.
• Search − Searches an element using the given index or by the value.
• Update − Updates an element at the given index.