Data Types & Memory

There are many data types that exist that let the computer know what data the programmer is using so that the program can compile and execute methods around that data type.

There are many different methods that only apply to certain data types, for
example, a string in Python has a .split() method which when used splits all of the string up into a list, if I were to have a variable t = “Hello, my
name is Billy, I am 19″ and then use the .split() method on it like so,
t.split(“,”), this will find all occurrences of a comma in the string
and split the whole string into a list. However, a data type such as float does
not have the .split() function so will give you an error if you were to try and
execute it.

There are 4 primitive data structures in Python: String, Integer, Float and Boolean which means these are the most basic types to be used within the language, there are however non-primitive data structures such as, arrays, lists, tuples, dictionaries etc.

Operators can be used on different data types if the data type has been casted to the correct one. For example, this code will not work since you cannot compare a string and an integer and produces a TypeError.

However if you change the code to cast the string to an integer, as you see here, it will work perfectly and display “Successful” in the console

Memory

When a computer compiles a program and executes it, it will store local variables on a stack within the memory and when the program enters a function that uses one of these variables it can find where the variable is allocated then when the program is out of the function the space is freed up within the memory.

Leave a Reply