top of page
Search

Programming with Python- Arrays


Array Programming

Arrays are a data structure which can hold a number of items / elements.

Each item / element of an array can be accessed by referring to its index number in the array.


furniture = ["table", "sofa", "chair", "bed"]

Here, we have an array called furniture, which stores the names of different items of furniture 🪑🛏.


The first item of the array is stored at index 0, and has value "table".


print (furniture[0])

This would print "table".


We can also change the value of an item, by setting it to something else.


furniture[2] = "armchair"

This would change the item located at index 2 ("chair"), to "armchair".


Let's say we have already created our array. We can add it to by appending a value.


furniture.append("coffee table")

This would add the item "coffee table" to the end of the array.


Have a go at creating different arrays in Python


Thanks ☺️

1,294 views

Recent Posts

See All
bottom of page