Math in IT — All About Arrays…

Meljcode
3 min readMay 9, 2022

What is an Array?

An Array is a data structure that can be used to store many items in one place, sort of like a house. If the house is an array, some of the things you may find in it include; doors, windows, and rooms.

Room’s are also an Array, as they store items. Let’s take a look inside… the Kitchen.

what’s inside the kitchen?

In programming, we can create a kitchen (array) and store its items. Here’s an example using Python:

what can we do with the items in the kitchen?

What can we do with an Array?

Access its values:

In an Array, every element is assigned a number called an index. Index numbers are consecutive integers starting from 0. For example, if we wanted to find the kettle in the kitchen array above, we can get it by specifying it’s index.

what would be the index of the fridge?

Modify its values:

Let’s add an item our Kitchen…

new dining table, who’s this?

Iterate over it:

If an array contains N elements, we can iterate over consecutive numbers from index 0 to index N − 1 and check every index. The length of an array can be found using the len() function.

N = len(kitchen)

In Python, we can iterate over a list using a ‘for loop’. Here’s an example:

Some basic Array operations:

Here are a few other useful Python list operations:

--

--

Meljcode

(neurodivergent) professional problem solver 🤓 passionate about technology 💻, education 🧮, mental health 🧠 & art 🎨