WEBVTT

00:00.480 --> 00:01.620
In programming.

00:01.620 --> 00:10.590
Whitespace refers to any non-printing characters such as spaces, tabs and end of line symbols.

00:10.590 --> 00:15.300
You can use whitespace to organize your output so it's easier for users to read.

00:15.600 --> 00:19.310
To add a tab to your text, use the character t.

00:20.760 --> 00:22.890
Here now we will print.

00:25.420 --> 00:26.880
He Oxley.

00:27.040 --> 00:29.050
Now, we will see this here.

00:29.050 --> 00:31.360
As you can see, we have a tab here.

00:32.370 --> 00:40.830
So let's actually print the Oxley without tab and see how many characters we are seeing now.

00:41.370 --> 00:41.970
Here.

00:43.440 --> 00:45.900
As you can see here, this is accelerated.

00:46.530 --> 00:50.280
This is auxiliary without the tab and this is auxiliary with the tab here.

00:51.860 --> 00:54.050
To add new lines in a string.

00:54.050 --> 00:55.910
You use the character n.

00:57.790 --> 00:58.180
Here.

00:58.180 --> 00:59.710
This is our new line.

00:59.710 --> 01:05.650
So this here is N right here.

01:08.130 --> 01:16.020
And you can also use combine tabs and newlines in a single string.

01:16.380 --> 01:19.320
So now the string here.

01:19.320 --> 01:21.270
Now let's actually end.

01:22.100 --> 01:25.100
T or actually it's pride, right?

01:25.100 --> 01:26.060
The languages.

01:26.060 --> 01:28.400
So languages.

01:28.940 --> 01:32.690
And here we will are Java Python and C plus plus.

01:32.690 --> 01:34.810
So n t.

01:36.160 --> 01:36.880
Python.

01:39.010 --> 01:39.730
Python.

01:39.730 --> 01:41.900
And here n t.

01:42.910 --> 01:45.690
C plus plus and.

01:48.040 --> 01:51.340
C plus plus and T and Java.

01:52.160 --> 01:53.120
Now.

01:53.880 --> 01:55.980
We will see this following output.

01:57.320 --> 01:57.960
That's it.

01:57.980 --> 02:01.480
As you can see here, we have tabs in here.

02:01.490 --> 02:06.890
We have new lines in here, tabs, new lines.

02:07.540 --> 02:08.440
And tabs.

02:08.890 --> 02:14.950
So here actually, it doesn't work like that because as you can see, the first overwrite the new lines

02:14.950 --> 02:18.790
and then tabs, new line tabs, new line tabs.

02:18.790 --> 02:19.930
So it will work.

02:19.930 --> 02:24.580
Firstly, new line here, then tab second.

02:25.390 --> 02:27.640
New Line third EP.

02:29.090 --> 02:33.710
Or new line shift and tab six here.

02:33.740 --> 02:34.760
So that's it.

02:35.740 --> 02:42.700
And the new license tabs will be very useful in the next few sections when you start to produce many

02:42.700 --> 02:45.760
lines of output from just a few lines of code.

02:45.790 --> 02:50.380
Now we can also strip the whitespaces in Python strings.

02:50.590 --> 02:53.680
So let me actually look at the lecture time if we have time.

02:53.770 --> 02:55.990
Yes, just at three minutes now.

02:55.990 --> 03:01.370
So extra whitespace can be confusing for programs programmers.

03:02.210 --> 03:02.920
Python.

03:03.730 --> 03:10.480
The programmers python and here let's actually let's delete this for sorry.

03:11.350 --> 03:14.890
So for programmers python and.

03:16.210 --> 03:18.880
Python look pretty much the same, right?

03:20.840 --> 03:26.300
But to a program they are two different actually.

03:26.300 --> 03:26.470
So.

03:26.660 --> 03:32.330
So so for program they are two different strings.

03:33.360 --> 03:42.570
Python the takes the extra space in second python and considers it significant.

03:43.340 --> 03:45.000
Unless you tell it otherwise.

03:45.020 --> 03:50.750
It's important to think about whitespace because often you will want to compare two strings.

03:50.750 --> 03:52.920
So determine whether they are the same.

03:52.940 --> 03:59.360
For example, one important instance might involve checking people's username when they log into a website.

03:59.360 --> 03:59.750
Right?

03:59.750 --> 04:07.430
So extra whitespace can be confusing in much simpler situations as well.

04:07.550 --> 04:11.300
Version of Python makes it easier to.

04:12.100 --> 04:13.270
Illuminate.

04:14.140 --> 04:18.400
Uh, extra whitespace from data that people enter.

04:18.670 --> 04:26.020
So Python can look at for extra whitespace on the right and the left side of a string.

04:26.020 --> 04:31.120
So to ensure that the whitespace no whitespace exists at the right side of a string.

04:31.120 --> 04:34.690
So you can use our script now.

04:36.050 --> 04:43.130
Uh, my my favorite language here is going to be.

04:44.790 --> 04:45.390
Python.

04:46.750 --> 04:49.210
And here we will use.

04:50.510 --> 04:50.830
Ops.

04:51.020 --> 04:54.800
Let's actually add whitespace here and now.

04:56.020 --> 05:00.520
We will print the my favorite language.

05:00.520 --> 05:04.690
And after that we will use my favorite language.

05:05.940 --> 05:06.420
That.

05:07.750 --> 05:14.290
Strip or strip or strip and that's it that we will print my favorite language.

05:14.320 --> 05:17.260
Language again, my favorite language again.

05:17.260 --> 05:18.610
And after that.

05:19.620 --> 05:20.220
Yeah, that's it.

05:20.430 --> 05:20.970
Yeah.

05:21.090 --> 05:22.440
Now let's run this.

05:28.560 --> 05:32.070
As you can see here, we got to.

05:32.900 --> 05:34.620
Same results.

05:34.670 --> 05:38.750
And here you will see that there is a white space here.

05:39.820 --> 05:44.980
And if you select this like that, you have a white spaces here.

05:45.770 --> 05:56.000
Because you in order to change this or show like this, you will write the script here and now you will

05:56.000 --> 05:57.020
see this here.

05:57.790 --> 06:00.710
Now Python is stripped.

06:01.150 --> 06:07.860
So the value associated with my favorite language contains extra whitespace at the end of a string.

06:07.870 --> 06:13.930
So when you ask Python for this value in a terminal session, you can see the whitespace at the end

06:13.930 --> 06:14.890
of the value.

06:16.220 --> 06:16.730
Right.

06:17.060 --> 06:26.330
So when the answer methods acts on the variable, my favorite language, this extra space is removed,

06:26.600 --> 06:27.950
as you can see here.

06:30.340 --> 06:34.060
However, it's only removed temporarily.

06:34.180 --> 06:43.750
So if you ask for the value of my favorite language, again right here, let's print my favorite language.

06:44.650 --> 06:45.610
The strings.

06:45.610 --> 06:48.280
Look, this looks the same here.

06:49.100 --> 06:49.570
Here.

06:49.830 --> 06:50.570
Here.

06:51.100 --> 06:53.350
So this has whitespace.

06:53.350 --> 06:55.960
This doesn't have whitespace here.

06:57.020 --> 06:59.600
And also this has white space.

07:00.050 --> 07:00.890
So.

07:01.820 --> 07:04.580
As I said, if you ask the value again.

07:06.610 --> 07:11.350
The strings look the same as when it was created, including the extra whitespace.

07:11.350 --> 07:19.270
So to remove the whitespace from the string permanently, you have to associate the script value with

07:19.270 --> 07:20.590
the variable name.

07:20.770 --> 07:21.790
Now.

07:22.530 --> 07:23.370
Let's.

07:24.980 --> 07:25.570
Here.

07:25.580 --> 07:31.460
After that, we will use instead of just writing the variable name like this.

07:32.800 --> 07:34.930
Here writing variable name like this.

07:34.960 --> 07:36.430
We will add this here.

07:36.970 --> 07:42.340
My favorite language equals my favorite language, our script.

07:42.370 --> 07:44.860
Now let's print the value.

07:44.890 --> 07:47.320
Print my favorite language.

07:50.230 --> 07:51.520
And here.

07:54.370 --> 07:55.300
That's it.

07:55.600 --> 07:58.210
So this is firstly the.

08:00.930 --> 08:02.370
White space version.

08:02.670 --> 08:07.560
And this is the version without the white space.

08:07.890 --> 08:12.330
And as you can see, we didn't use the strip function in.

08:13.450 --> 08:15.220
Um, my favorite language.

08:15.340 --> 08:21.370
Because now, after this third line, my favorite language.

08:22.210 --> 08:24.610
My favorite language is.

08:25.820 --> 08:28.250
Value is equal to this.

08:28.700 --> 08:34.610
Whenever you use it, this variable is the name of your my favorite language variable.

08:35.480 --> 08:36.260
So.

08:37.380 --> 08:46.020
In this example, we start with with the value that has whitespace at the beginning and let's actually

08:46.020 --> 08:46.740
yes, yes.

08:46.740 --> 08:53.250
It will be more good practice to use the whitespace on the beginning.

08:53.250 --> 08:53.790
Right.

08:53.940 --> 08:58.300
So now let's add whitespace at the beginning as well.

08:58.320 --> 09:05.610
Now, as you can see here, yes, it would fix our white spaces at the end in the second here because

09:05.610 --> 09:07.620
we don't have the white spaces here.

09:07.620 --> 09:09.480
But I'm sorry.

09:09.510 --> 09:11.280
Here we have white space here.

09:12.580 --> 09:15.580
Button in the start, but not in the end.

09:15.580 --> 09:20.830
So we have white spaces in second in the left, but not on the right.

09:20.830 --> 09:26.560
But here we have white spaces on both sides.

09:26.920 --> 09:33.010
So in order to fix this, we will use our strip here.

09:34.030 --> 09:34.990
So.

09:36.680 --> 09:40.220
Now we will use my favorite language again.

09:40.220 --> 09:43.940
And after that, my favorite language.

09:43.940 --> 09:45.910
That all strip, strip.

09:46.130 --> 09:48.920
Now let's try this out.

09:49.130 --> 09:53.270
And as you can see here, we deleted all the white spaces.

09:53.270 --> 09:59.720
But in the first example that we without manipulation of our text you are seeing here, we have two

09:59.720 --> 10:03.110
white spaces on the left and the right here.

10:04.460 --> 10:09.260
But in the second, we don't have any white spaces here.

10:09.680 --> 10:10.490
That's it.

10:10.520 --> 10:15.590
Because we use these functions are strip and strip.
