In the previous lesson, you have discovered what variables were, and so far you've only used variables
to store integer numbers.
So round numbers as you can see, like this.
But in fact there are many more types you can use.
Let's discover the most important ones now that you will basically need in all your future programs.
So I'm going to remove all of that.
You can save it and reuse later to follow the videos again if you want.
And we're going to start to create a variable with.
So let's name it a.
So just a quick note I just told you about using meaningful names for variables okay.
We're going to do that in a minute.
For now I just use a.
So we just focus on the data types for variables.
And then later on we're going to use more meaningful names.
So the first thing you've seen is for example we can do a is equal to five.
That is a integer number I can print a okay.
So I can run that and it's going to print five.
And somehow well I'm not sure exactly why I have this.
Well, if you have the same, you can just close.
It's probably a problem with my keyboard, but that's not really a problem.
Just start again.
So this number, this round number is called the integer.
It can be five.
It can be a big number.
It can be a small number.
It can be zero.
It can also be a negative number okay.
So for example minus ten that's going to work as well.
That's an integer number.
Then the second kind of data type is float number.
So float number is simply a number but with a decimal with a comma.
So for example 3.14 I can run that okay 3.14.
And you're going to use a point okay.
So 3.14 it can also be a negative number.
Well let's run this -3.14 okay.
So you have two ways of representing a number in Python.
Basically you have the round numbers which are integers and the float numbers okay.
For decimal numbers then we have strings.
So we have actually used strings before.
I just need to put as I'm going to remove that and I just need to put a double quotes twice okay.
And then I can write any piece of text.
So any piece of text you can see, I can write anything I want.
And that's going to be printed here.
Okay.
I print a which is this chain of characters also called a string.
And the fourth type that we are going to see here is called Boolean.
So what is a Boolean?
In a boolean you can only put two different values.
That's going to be true or false.
And there are special keywords for that okay.
You can see true here we have a syntax highlighting okay.
It's it's purple and bold.
And I have also false okay.
So if I run this you can see now we have false.
And this kind of value is quite useful if you want to check for example if a push button is pressed
is it true or is it false.
And you can use a boolean value okay.
And for this you have the two keywords true and false.
Note that it's very important to write them exactly like this with a f uppercase.
If I write false like this, look at what's going to happen.
We have an error because false is not defined here.
It thinks that false is going to be some variables that we have defined before okay.
You need to use the f uppercase okay false keyword because this is a recognized keyword.
And if I put true then it's going to be true okay.
So we have integers float numbers strings and booleans.
For now we're going to keep using those.
And you can really do a lot of things already with those four data types.
And if you are not sure about the type that you have set inside a variable, you can use the function.
So there is another function for now you know print but there is another function is called type.
You can see also with syntax highlighting here.
So I'm going to write type open and close parentheses and then put a variable inside.
And let's press play here.
And you can see class.
So don't worry about the class here.
But you can see bull that's a boolean.
And what happened here is that you can see that we have a functionality inside another functionality.
So that's perfectly valid.
What's going to happen is that first this is going to be evaluated.
So it's going to fetch a and then get the type of a and then print the result of that.
So print the type of a.
So here you have bull.
Um if I put for example three then the type of three is going to be int okay.
If I put 3.14 this is going to be float.
But now for example if I put 3.0 just 3.0 instead of three, you can see that this is also considered
as a float.
Okay.
So there is a difference between 3 and 3.0.
As you can see here.
And now if I put quotes like this, if we print a we're going to see three.
But the type as you can see this is a string.
And once again I have this error.
So if you put quotes, whatever inside is going to be a string.
Okay.
Even if it's a number okay.
Even if you type true, you can see that's still a string.
So just in case, if you are doubting about the type that is inside a variable, you can use the type
here.
And you can print it to make sure that you are using the correct type, because this could lead to some
errors in the future.
So let's come back to integer number.
Here we have a int.
And as you can see the type of a variable is dynamically set when you create the variable okay.
With languages like C, C plus plus and Java for example, you have to specify the type.
Also, when you first use the variable you have to do that manually, not in Python.
So it means that you can put whatever you want inside A and A is going to become the type of that value
here.
And it means also that you could change the variable's type anytime in your program.
So now a is an integer.
But I could say then that A is hello and let's print the type of A again.
Let's run.
And you can see a was first an integer and now A is a string.
So this is possible in Python.
However this practice is strongly discouraged even if you can theoretically do it in practice.
This is a good way to mess up your programs and get a lot of errors.
So when you have set a variable, you can change it to any value after that, but stick to values that
are of the same type as the original one.
One advice to avoid making mistakes with types is simply to use meaningful names for your variables.
So for example, let's remove that and let's use Wi-Fi underscore name okay.
And put the Wi-Fi name so your Wi-Fi.
A variable named Wi-Fi name.
Well it's probably going to contain a string.
So you will not modify it later for an integer or a boolean or a float.
So here's a meaningful name, for example, for a string.
Then let's say you are going to store a temperature.
So temperature.
Well we use the integer before but you could use a float number.
So for example 20.5.
Then for example you want to create a user age.
So you want to store the user age.
User age is going to be an integer number.
So it's no mistake with this.
And finally let's say you want to check if the camera that you have plugged to the Raspberry Pi is still
alive.
So let's say alive means connected here.
So you can create a variable name is alive is equal to true okay.
And that's going to be a boolean true or false.
All right.
So as best practice I really encourage you to think about a variable name.
Anytime you're going to create a variable and give a name that is meaningful.
All right.
To recap on this lesson, you can use different types of variables depending on the value you want to
store.
For example, integers, float numbers, strings, and booleans.