All About Lists (aka Arrays) in Python?

Nouer Uz Zaman
3 min readApr 12, 2022

--

In any programming language arrays are the most used data structure. So, we can say if you want to learn anything about data structures then start with arrays. In Python, arrays are known as Lists. In other popular programming languages like C++ or Java it is known as arrays. If want to be more specific Python lists are “dynamic arrays” whereas JAVA/C++ actually have two types of arrays which are dynamic and static (cannot insert elements beyond the upper limit).

In most simplest terms, a list object is anything which can be defined by squared brackets ([]) like the example below. So, by intuition if you write anything and put squared brackets next to it then it becomes a list.

Next point, within lists the index position starts at 0. Index position is basically the count of numbers. Say we have a list of following numbers: 30,40,50,60,70. If we assign a counter next to these numbers to know how many numbers we have then it would be 5. However in programming languages (including VBA), the counter starts at 0 not 1. Thus, the number 320 from the stock_prices list has index position of 2 not 3.Get into the habit whenever you think of index position substract the number by 1.

Now that is what we see from the outside how does it look from the inside. In memory it looks something like below. The Random Access Memory (RAM) is used when you run a code on the CPU which stores all the data in memory.

So, when we run the Python code to generate stock prices variable this variable is stored in specific memory locations. Next to the stock prices you will see hexadecimal number (e.g. 0x00500) which are the memory locations or addresses on RAM.

However, if we go deeper the numbers are actually first converted into a binary number and then stored in RAM. So, the first index value 298 actually equals 100101010 and each single digit number is a byte.

1 and 0 are integer numbers and whenever we use integers we use 4 bytes to store the number. Each byte constitutes of 8 bites.

So, when we look into from deeper level then each number is defined by 4 bytes where each byte constitutes of 8 bites.

Python Functions

Within Python you can use following functions where are related to a list.

  1. df= [1,4,5,8,10]
  2. df.insert(1,6), df= [1,6,4,5,8,10]
  3. df.remove(1), df=[1,5,8,10]

--

--