As we are just getting started we will deal with three kinds of data: “String”, “Integer” and “Float”. Each of this types handles a different “species” of data, even if variables may seem the same they are in reality VERY different from each other.
Let us imagine we have a variable “x = 5.4”, we will analyze what will happen to the value of this variable in all three data types:
First we have the STRING, which represents ANY symbol, but has no actual numerical value. Meaning that we can indeed print (x) and the computer will give us a beautiful 5.5, but if we try to do x – 1, an error will appear. This is because x represents a symbol, 5.4, but not a value, and since there is no value to subtract 1 from, BOOM!
In cases like this we use the INTEGER, which stands for a numerical value. This way when we do again the operation x – 1, we will be given the value of 4…?? And you may be wondering ¿what happened to the “.4”? An Integer is a ROUND number, as in NO DECIMALS. This is why it gets rid of the decimal values in order to keep going. You can still print the number though only by Integer terms: print (x)  5.
But if you DO want do use decimals you can make use of the FLOAT type. The name “Float” stands for “floating point”, meaning “decimals, yey!”. For instance if we print (x) ye will get the full “5.4” we want, and if we do the operation x – 1 the result will be 4.4.
ATTENTION: Integer and Float data can only be numbers, not symbols.
You can freely change the type of data a value is in by doing the following:
Let’s say the variable name is “x” and we ignore the type of value it will be. For instance, python sets the data type of all values as strings, because of the simple reason that “¡Anything can be a string!”, we just need to change this according to what we want to do.
If we need a string, just leave it like so.
If we need an Integer, we write the following: “x = int (x)”, with this we tell the computer “take the X we had, and just turn it into an integer, of course with the same value as the original X”
And if we want to turn it to a Float, we do basically the same: “x = float (x)”.
The data type you use depends on your needs, so you need to have a very clear idea of what you want to do in order to accurately manage your data types.

spudlol.0.0

CC BY 4.0 Basic data types… by juansalvadorfernandez is licensed under a Creative Commons Attribution 4.0 International License.