WEBVTT

00:00.050 --> 00:05.450
In the previous lesson, you have discovered what variables were, and so far you've only used variables

00:05.450 --> 00:07.580
to store integer numbers.

00:07.580 --> 00:10.280
So round numbers as you can see, like this.

00:10.280 --> 00:13.280
But in fact there are many more types you can use.

00:13.280 --> 00:20.030
Let's discover the most important ones now that you will basically need in all your future programs.

00:20.030 --> 00:23.120
So I'm going to remove all of that.

00:23.570 --> 00:28.070
You can save it and reuse later to follow the videos again if you want.

00:28.100 --> 00:31.220
And we're going to start to create a variable with.

00:31.250 --> 00:32.570
So let's name it a.

00:32.600 --> 00:37.880
So just a quick note I just told you about using meaningful names for variables okay.

00:37.910 --> 00:39.290
We're going to do that in a minute.

00:39.290 --> 00:41.060
For now I just use a.

00:41.090 --> 00:44.300
So we just focus on the data types for variables.

00:44.300 --> 00:46.730
And then later on we're going to use more meaningful names.

00:46.730 --> 00:51.050
So the first thing you've seen is for example we can do a is equal to five.

00:51.080 --> 00:56.510
That is a integer number I can print a okay.

00:56.510 --> 01:01.250
So I can run that and it's going to print five.

01:01.340 --> 01:04.750
And somehow well I'm not sure exactly why I have this.

01:04.780 --> 01:07.690
Well, if you have the same, you can just close.

01:07.690 --> 01:12.940
It's probably a problem with my keyboard, but that's not really a problem.

01:12.940 --> 01:14.200
Just start again.

01:14.200 --> 01:18.010
So this number, this round number is called the integer.

01:18.040 --> 01:19.150
It can be five.

01:19.180 --> 01:20.500
It can be a big number.

01:20.500 --> 01:21.760
It can be a small number.

01:21.760 --> 01:22.480
It can be zero.

01:22.480 --> 01:24.760
It can also be a negative number okay.

01:24.790 --> 01:27.820
So for example minus ten that's going to work as well.

01:27.820 --> 01:29.380
That's an integer number.

01:29.380 --> 01:33.490
Then the second kind of data type is float number.

01:33.490 --> 01:37.660
So float number is simply a number but with a decimal with a comma.

01:37.660 --> 01:44.590
So for example 3.14 I can run that okay 3.14.

01:44.620 --> 01:46.390
And you're going to use a point okay.

01:46.420 --> 01:49.690
So 3.14 it can also be a negative number.

01:49.720 --> 01:54.130
Well let's run this -3.14 okay.

01:54.160 --> 01:57.070
So you have two ways of representing a number in Python.

01:57.070 --> 02:02.110
Basically you have the round numbers which are integers and the float numbers okay.

02:02.140 --> 02:05.200
For decimal numbers then we have strings.

02:05.200 --> 02:07.940
So we have actually used strings before.

02:07.970 --> 02:14.150
I just need to put as I'm going to remove that and I just need to put a double quotes twice okay.

02:14.180 --> 02:16.550
And then I can write any piece of text.

02:16.550 --> 02:22.250
So any piece of text you can see, I can write anything I want.

02:22.280 --> 02:23.990
And that's going to be printed here.

02:24.020 --> 02:24.260
Okay.

02:24.290 --> 02:31.460
I print a which is this chain of characters also called a string.

02:31.460 --> 02:35.870
And the fourth type that we are going to see here is called Boolean.

02:35.870 --> 02:37.490
So what is a Boolean?

02:37.490 --> 02:41.180
In a boolean you can only put two different values.

02:41.180 --> 02:43.400
That's going to be true or false.

02:43.400 --> 02:45.320
And there are special keywords for that okay.

02:45.350 --> 02:49.250
You can see true here we have a syntax highlighting okay.

02:49.250 --> 02:51.530
It's it's purple and bold.

02:51.530 --> 02:55.040
And I have also false okay.

02:55.040 --> 02:58.640
So if I run this you can see now we have false.

02:58.640 --> 03:03.560
And this kind of value is quite useful if you want to check for example if a push button is pressed

03:03.590 --> 03:05.420
is it true or is it false.

03:05.450 --> 03:07.310
And you can use a boolean value okay.

03:07.340 --> 03:09.890
And for this you have the two keywords true and false.

03:09.920 --> 03:15.220
Note that it's very important to write them exactly like this with a f uppercase.

03:15.250 --> 03:18.970
If I write false like this, look at what's going to happen.

03:18.970 --> 03:22.510
We have an error because false is not defined here.

03:22.510 --> 03:26.710
It thinks that false is going to be some variables that we have defined before okay.

03:26.740 --> 03:33.550
You need to use the f uppercase okay false keyword because this is a recognized keyword.

03:33.610 --> 03:38.080
And if I put true then it's going to be true okay.

03:38.110 --> 03:42.250
So we have integers float numbers strings and booleans.

03:42.250 --> 03:43.840
For now we're going to keep using those.

03:43.840 --> 03:47.950
And you can really do a lot of things already with those four data types.

03:48.250 --> 03:54.100
And if you are not sure about the type that you have set inside a variable, you can use the function.

03:54.100 --> 03:59.080
So there is another function for now you know print but there is another function is called type.

03:59.710 --> 04:03.130
You can see also with syntax highlighting here.

04:03.130 --> 04:08.410
So I'm going to write type open and close parentheses and then put a variable inside.

04:08.440 --> 04:11.020
And let's press play here.

04:11.020 --> 04:12.670
And you can see class.

04:12.670 --> 04:14.440
So don't worry about the class here.

04:14.450 --> 04:16.550
But you can see bull that's a boolean.

04:16.550 --> 04:22.760
And what happened here is that you can see that we have a functionality inside another functionality.

04:22.760 --> 04:24.890
So that's perfectly valid.

04:24.890 --> 04:29.930
What's going to happen is that first this is going to be evaluated.

04:30.380 --> 04:37.880
So it's going to fetch a and then get the type of a and then print the result of that.

04:37.880 --> 04:39.260
So print the type of a.

04:39.290 --> 04:41.060
So here you have bull.

04:41.780 --> 04:47.660
Um if I put for example three then the type of three is going to be int okay.

04:47.690 --> 04:52.430
If I put 3.14 this is going to be float.

04:52.520 --> 05:00.980
But now for example if I put 3.0 just 3.0 instead of three, you can see that this is also considered

05:00.980 --> 05:02.150
as a float.

05:02.180 --> 05:02.660
Okay.

05:02.690 --> 05:06.380
So there is a difference between 3 and 3.0.

05:07.190 --> 05:08.210
As you can see here.

05:08.210 --> 05:13.760
And now if I put quotes like this, if we print a we're going to see three.

05:13.760 --> 05:17.210
But the type as you can see this is a string.

05:17.210 --> 05:19.090
And once again I have this error.

05:19.450 --> 05:23.050
So if you put quotes, whatever inside is going to be a string.

05:23.080 --> 05:23.290
Okay.

05:23.320 --> 05:25.060
Even if it's a number okay.

05:25.090 --> 05:29.980
Even if you type true, you can see that's still a string.

05:29.980 --> 05:36.220
So just in case, if you are doubting about the type that is inside a variable, you can use the type

05:36.220 --> 05:36.340
here.

05:36.340 --> 05:42.100
And you can print it to make sure that you are using the correct type, because this could lead to some

05:42.100 --> 05:43.390
errors in the future.

05:43.390 --> 05:45.670
So let's come back to integer number.

05:45.670 --> 05:47.770
Here we have a int.

05:47.770 --> 05:54.580
And as you can see the type of a variable is dynamically set when you create the variable okay.

05:54.610 --> 05:59.950
With languages like C, C plus plus and Java for example, you have to specify the type.

05:59.950 --> 06:05.020
Also, when you first use the variable you have to do that manually, not in Python.

06:05.020 --> 06:11.350
So it means that you can put whatever you want inside A and A is going to become the type of that value

06:11.380 --> 06:12.010
here.

06:12.010 --> 06:17.530
And it means also that you could change the variable's type anytime in your program.

06:17.530 --> 06:20.080
So now a is an integer.

06:20.080 --> 06:27.570
But I could say then that A is hello and let's print the type of A again.

06:28.800 --> 06:30.270
Let's run.

06:31.020 --> 06:35.250
And you can see a was first an integer and now A is a string.

06:35.250 --> 06:37.560
So this is possible in Python.

06:37.590 --> 06:44.130
However this practice is strongly discouraged even if you can theoretically do it in practice.

06:44.160 --> 06:48.450
This is a good way to mess up your programs and get a lot of errors.

06:48.450 --> 06:54.870
So when you have set a variable, you can change it to any value after that, but stick to values that

06:54.870 --> 06:57.570
are of the same type as the original one.

06:57.600 --> 07:03.060
One advice to avoid making mistakes with types is simply to use meaningful names for your variables.

07:03.060 --> 07:09.930
So for example, let's remove that and let's use Wi-Fi underscore name okay.

07:09.960 --> 07:14.310
And put the Wi-Fi name so your Wi-Fi.

07:15.810 --> 07:17.370
A variable named Wi-Fi name.

07:17.370 --> 07:19.890
Well it's probably going to contain a string.

07:19.890 --> 07:24.510
So you will not modify it later for an integer or a boolean or a float.

07:24.520 --> 07:28.240
So here's a meaningful name, for example, for a string.

07:28.270 --> 07:32.350
Then let's say you are going to store a temperature.

07:33.070 --> 07:34.210
So temperature.

07:34.210 --> 07:38.980
Well we use the integer before but you could use a float number.

07:38.980 --> 07:41.140
So for example 20.5.

07:41.170 --> 07:43.600
Then for example you want to create a user age.

07:43.600 --> 07:45.610
So you want to store the user age.

07:45.640 --> 07:48.070
User age is going to be an integer number.

07:48.070 --> 07:50.140
So it's no mistake with this.

07:50.140 --> 07:55.780
And finally let's say you want to check if the camera that you have plugged to the Raspberry Pi is still

07:55.780 --> 07:56.290
alive.

07:56.290 --> 07:58.540
So let's say alive means connected here.

07:58.540 --> 08:05.020
So you can create a variable name is alive is equal to true okay.

08:05.020 --> 08:07.300
And that's going to be a boolean true or false.

08:07.330 --> 08:07.720
All right.

08:07.720 --> 08:12.460
So as best practice I really encourage you to think about a variable name.

08:12.460 --> 08:16.750
Anytime you're going to create a variable and give a name that is meaningful.

08:16.780 --> 08:17.290
All right.

08:17.290 --> 08:23.560
To recap on this lesson, you can use different types of variables depending on the value you want to

08:23.590 --> 08:24.010
store.

08:24.010 --> 08:28.870
For example, integers, float numbers, strings, and booleans.
