Python Array – Arrays are a fundamental, basic, and must-to-know data structure and an important part of most programming languages. In Python, these are the containers that are able to store more than one item of the same type at the same time.
To be specific, these are an ordered collection of elements where every value is of the same data type. That is the most important thing in Python arrays – that they can only hold a sequence of multiple items that are of the same type.
NOTE – Lists and arrays may behave similarly but the main difference between the two is that lists can hold multiple elements of different data types but not arrays.
For example –
Creating an array of foodItems
foodItems = [“bread”, “butter”, “jam”]
Accessing the elements:
We can access the elements of the array by their index. So,
foodItems=”bread” foodItems=”butter” foodItems=”jam”
and so on,
Length of the array – It can be found out by
x = len(foodItems)
We can perform these operations on array items:
1. Looping over them
- Adding the array elements
- Removing array elements