Lists vs Arrays in Python

Blake Tolman
3 min readJan 22, 2021

--

When using python, it is often that a series of data entries need to be stored. The typical go to feature that is built into Python are Lists. However there is another common way to save a series of data and that is an Array. While they share similar functions, there are differences that would change when and how to use each function.

To begin with and a List has a couple key features:

  1. Lists are enclosed in brackets List = [ item:1, item:2, item3, etc ]
  2. Lists are ordered
  3. List are mutable
  4. Lists items do not have to be unique
  5. List can contain multiple data types
  6. Lists are indexed starting at [0]

Arrays on the other hand are going to share all the above qualitees with a few exceptions:

  1. An array has to be declared
  2. Arrays are only one data type
  3. Arrays are more efficient at storing data
  4. Arrays can directly handle math computations

With some key features stated we can begin to dive a little more in depth into how these functions work. An array has to be called by first importing the necessary libraries, either numpy or Array.

Once imported an Array can be created and altered as needed. One of the most common reasons to have and Array is to store a series of numbers. Arrays are unique in that direct math calculations can be applied to each individual element in the Array.

Input:

Output:

If the same calculator was attempted with a list and error message would be returned as list main objective is just to store data.

Arrays go on to share traits with lists, being able to store a series of other data types to like strings. Knowing the difference between the two functions allows for more efficient coding when the end goal is known. A list should be used when storing a short sequence of items that wont have mathematical operations used on it. Arrays are best used when storing a long sequence of items as it stores data more efficiently or when operations will be used.

--

--

Blake Tolman
Blake Tolman

No responses yet