WEBVTT

00:00.750 --> 00:02.010
When working with strings.

00:02.040 --> 00:05.160
Another common task is to remove a prefix.

00:05.160 --> 00:15.440
Consider a URL with the common prefix https and we want to remove this prefix so we can focus on just

00:15.450 --> 00:21.270
a part of the URL that the users need to enter into an address bar.

00:21.300 --> 00:22.920
Here's how you do that.

00:22.950 --> 00:26.940
Firstly, we will enter the auxiliary URL.

00:27.300 --> 00:31.800
URL and here we will enter.

00:32.680 --> 00:44.380
Http oxley.com and is actually Udemy URL but in this case Udemy url will be https.

00:44.410 --> 00:44.980
Right.

00:45.010 --> 00:46.780
It will have different.

00:47.710 --> 00:48.280
Perfect.

00:50.180 --> 00:53.300
And here we will udemy.com.

00:54.050 --> 00:55.010
Now.

00:57.810 --> 00:59.010
Let's do this.

00:59.040 --> 00:59.640
Oxalate.

00:59.640 --> 01:02.090
That oxalate equals oxalate.

01:02.760 --> 01:07.590
Remove prefix http http.

01:08.880 --> 01:09.450
Here.

01:09.450 --> 01:13.710
And for Udemy we will use different https, right?

01:15.620 --> 01:18.080
What Udemy URL.

01:19.210 --> 01:21.730
Udemy url dot remove prefix.

01:21.790 --> 01:23.320
Http here.

01:23.350 --> 01:33.280
So if we do this and let's print this after that print url and print Udemy url.

01:33.280 --> 01:34.000
That's it.

01:34.860 --> 01:36.540
Now let's run this.

01:36.960 --> 01:38.190
And as you can see here.

01:38.190 --> 01:47.940
Yes, excellent Comet changed, but all udemy.com is left unchanged because we need to add s here to

01:47.940 --> 01:49.610
completely fix this.

01:49.620 --> 01:52.920
And here, as you can see here, com is changed.

01:52.920 --> 02:02.880
So you enter the name of the variable followed by a dot and then the method remove prefix.

02:03.210 --> 02:09.210
So inside the parentheses enter the prefix you want to remove from the original string.

02:10.380 --> 02:16.320
So like the methods for removing whitespace remove prefix leaves the original string unchanged.

02:16.350 --> 02:24.510
So if you want to keep the new value with the prefix removed, either reassign to the original variable

02:24.690 --> 02:28.230
like I did here or assign it to a new variable.

02:28.710 --> 02:34.920
So when you see a URL in an address bar, uh, the http.

02:36.010 --> 02:38.290
This part isn't shown.

02:38.320 --> 02:43.660
The browser is probably using a method like remove prefix.

02:44.050 --> 02:45.460
Behind the scenes.

02:46.490 --> 02:53.720
Let's actually now learn about how to avoid syntax errors with strings.

02:53.780 --> 03:01.400
So one kind of error that you might see with some regularity is a syntax error.

03:01.430 --> 03:09.260
A syntax error occurs when Python doesn't recognize a section of your program as valid python code.

03:09.290 --> 03:15.890
For example, if you use apostrophe within a single quotes, you will produce error.

03:15.920 --> 03:22.700
This happens because Python interprets everything between the first single quote and the apostrophe

03:22.730 --> 03:23.900
as a string.

03:23.930 --> 03:27.590
So it then tries to interpret the rest of.

03:29.620 --> 03:34.810
Uh, interpret the rest of the text as a python code, which causes errors.

03:34.810 --> 03:39.700
So here's how you use the single and the double quotes correctly.

03:39.850 --> 03:43.000
So now we will enter this here.

03:43.120 --> 03:46.210
Now I will share this quotes with you.

03:46.210 --> 03:47.050
So.

03:49.060 --> 03:51.070
Example one.

03:52.790 --> 03:53.270
Here.

03:55.060 --> 03:55.990
Now.

04:13.430 --> 04:14.360
I'll do this.

04:14.640 --> 04:14.900
That's.

04:16.630 --> 04:17.830
And now.

04:19.140 --> 04:19.560
Um.

04:25.970 --> 04:27.860
Now, let's actually write this here.

04:28.340 --> 04:33.110
As we said, the message here one.

04:33.950 --> 04:40.200
Oh, one of the one of the titans of.

04:41.600 --> 04:46.580
Fighters strength is its diverse.

04:53.700 --> 04:54.900
Yeah, it's.

04:55.080 --> 04:56.580
Is it?

04:58.040 --> 04:59.270
Diverse.

05:01.400 --> 05:02.300
Community.

05:03.240 --> 05:03.900
Here.

05:03.900 --> 05:05.550
We will print this message.

05:06.060 --> 05:06.810
Message?

05:08.610 --> 05:09.990
I was, actually.

05:13.320 --> 05:16.710
Now we will create a text file here and.

05:19.030 --> 05:19.690
Here.

05:19.690 --> 05:30.160
The first rope appears inside a set of double quotes so the python interpreter has no trouble executing

05:30.160 --> 05:31.720
and running this command.

05:31.720 --> 05:33.760
So it's okay for now.

05:34.300 --> 05:37.480
However, if you use single quotes.

05:38.330 --> 05:43.760
Python cannot identify where the string should end.

05:44.060 --> 05:50.300
So here we will get an error and this code will not compile because as you can see, we have an error

05:50.300 --> 05:51.650
in line one message.

05:51.810 --> 05:56.020
The python's strength is its diverse community.

05:56.030 --> 05:57.830
Invalid syntax.

05:59.790 --> 06:03.330
And here you will see this error something.

06:03.540 --> 06:11.130
And in the output you can see that error occurs right after the final single quote here.

06:13.690 --> 06:20.740
And this syntax error indicates that the interpreter doesn't recognize something in the code as valid

06:20.770 --> 06:21.250
python code.

06:21.280 --> 06:21.660
Right.

06:21.670 --> 06:28.780
And it thinks the problem might be a string that's not quoted correctly and the errors can.

06:29.680 --> 06:34.590
From a variety of sources, and I will point out some common ones as they arise.

06:34.600 --> 06:40.060
So you might see syntax errors often as you learn to write proper python code.

06:40.420 --> 06:45.160
So syntax errors are also the least specific kinds of errors.

06:45.160 --> 06:51.130
So they can be difficult and frustrating to identify and correct.

06:51.130 --> 06:59.140
So if you get stuck on a particular step or an error, you can ask me and I will answer them immediately.
