You are on page 1of 2

Python arrays:

An array is a collection of similar data elements stored at contiguous memory locations. It is the
simplest data structure where each data element can be accessed directly by only using its index
number.
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.
Python arrays are used when you need to use many variables which are of the same type. It can also
be used to store a collection of data. The arrays are especially useful when you have to process the
data dynamically. Python arrays are much faster than list as it uses less memory.
Array Representation:
Arrays can be declared in various ways in different languages. Below is an illustration

As per the above illustration, following are the important points to be considered.
 Index starts with 0.
 Array length is 10 which means it can store 10 elements.
 Each element can be accessed via its index. For example, we can fetch an element at
index 6 as 70
Basic Operations
Following are the basic operations supported by an array.
 Traverse − 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.

In Python, Strings are arrays of bytes representing Unicode characters. It's possible to access
individual characters of a string by using array-like indexing . Like an array data type that has items
that correspond to an index number , each of a string's characters also correspond to an index number,
starting with the index number 0.
You can make any of these positive or negative numbers for indexing. The meaning of the positive
numbers is straightforward (from start), but for negative numbers, just like indexes in Python, you
count backwards from the end for the start and stop.
Negative Indexing
In Python, negative indexing starts from the end.
str ="python "
print(str[-4 : -1])
OUTPUT:
tho

You might also like