Ryan the Data Guy
Published in

Ryan the Data Guy

Python and Computer Memory

I’ve been taught how Python uses variables stored in computer memory to access a value in a different memory address. For the most part, I understood it but there are a few things I didn’t exactly understand. You’ll read about them further down and though I don’t think they’re major, I do kind of want to know.

If I’m interpreting this correctly:

For example, when a spreadsheet program calculates the average of a group of numbers, the program first adds up all the numbers then counts how many there are and then does the appropriate division.

All of these values are stored in computer memory. For the purposes of this course, we’ll think of computer memory as being a very long list of storage locations, each of which has a unique number called the memory address.

So where we would normally evaluate 4 + 4 / 2 while writing as, the computer does it in a different way.

  • It takes each value 4 and 4 and places them into memory, so let’s say x34, x35 and x36 respectively (I know this isn’t how addresses looks).
  • It should take 4 from x35 and divide it by 2 form x36 because of BEDMAS.
  • Then place the result 2 in another memory address, let’s say x37.
  • Then take 4 from x34 and add it to 2 from x37 to get 6 and place that in x38.

It sounds correct, but I’ve been here before where my interpretation was fully correct.

Variable: a named location in computer memory

In Python’s case when we create a variable which is stored in a separate area in memory, we indicate to the variable which memory address (RAM?) the assigned value is located.

Yes, I’m right. https://en.wikipedia.org/wiki/Computer_memory. It’s always going to be the case that we know but not what something is. It’s an interesting phenomenon.

So if we have variable alpha and it’s assigned to memory location x34 then whatever is in x34 will be used by alpha. Now one thing I’m curious about now is if alpha is assigned a new value, will it then use a different memory address? Such as x35 or x99.

Terminology I’m told to remember:

  • (1) A value has a memory address,
  • (2) a variable contains to a memory address,
  • (3) a variable refers to a value,
  • (4) a variable points to a value.

Before I’m told what all that means I want to take a guess.
(1) and (2): I already talked about what these mean above.
(3) and (4): I’m unsure what the difference between ‘refers’ and ‘points’ are. If I have to take a guess I’m going to assume (3) is stating that the variable is making known that a value has been assigned to this variable. (4) is stating that if the variable is called it will return the value.

The examples of use given were:

  • Value 8.5 has memory address x34,
  • variable shoe_size contains memory address x34,
  • the value of shoe_size is 8.5,
  • shoe_size refers to value 8.5,
  • shoe_size points to value 8.5.

After finishing the video.. it didn’t answer whether I was correct. So until I get a clear answer (maybe later on in my learning journey or maybe I’ll ask StackOverflow or Reddit for an answer) I’ll go with my guess.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ryan Velasco

I love gaming especially old-school jRPGs, I love them to this day. Now I’ve come to love automating everything and placing things into databases. Super fun.