When working with strings.
Another common task is to remove a prefix.
Consider a URL with the common prefix https and we want to remove this prefix so we can focus on just
a part of the URL that the users need to enter into an address bar.
Here's how you do that.
Firstly, we will enter the auxiliary URL.
URL and here we will enter.
Http oxley.com and is actually Udemy URL but in this case Udemy url will be https.
Right.
It will have different.
Perfect.
And here we will udemy.com.
Now.
Let's do this.
Oxalate.
That oxalate equals oxalate.
Remove prefix http http.
Here.
And for Udemy we will use different https, right?
What Udemy URL.
Udemy url dot remove prefix.
Http here.
So if we do this and let's print this after that print url and print Udemy url.
That's it.
Now let's run this.
And as you can see here.
Yes, excellent Comet changed, but all udemy.com is left unchanged because we need to add s here to
completely fix this.
And here, as you can see here, com is changed.
So you enter the name of the variable followed by a dot and then the method remove prefix.
So inside the parentheses enter the prefix you want to remove from the original string.
So like the methods for removing whitespace remove prefix leaves the original string unchanged.
So if you want to keep the new value with the prefix removed, either reassign to the original variable
like I did here or assign it to a new variable.
So when you see a URL in an address bar, uh, the http.
This part isn't shown.
The browser is probably using a method like remove prefix.
Behind the scenes.
Let's actually now learn about how to avoid syntax errors with strings.
So one kind of error that you might see with some regularity is a syntax error.
A syntax error occurs when Python doesn't recognize a section of your program as valid python code.
For example, if you use apostrophe within a single quotes, you will produce error.
This happens because Python interprets everything between the first single quote and the apostrophe
as a string.
So it then tries to interpret the rest of.
Uh, interpret the rest of the text as a python code, which causes errors.
So here's how you use the single and the double quotes correctly.
So now we will enter this here.
Now I will share this quotes with you.
So.
Example one.
Here.
Now.
I'll do this.
That's.
And now.
Um.
Now, let's actually write this here.
As we said, the message here one.
Oh, one of the one of the titans of.
Fighters strength is its diverse.
Yeah, it's.
Is it?
Diverse.
Community.
Here.
We will print this message.
Message?
I was, actually.
Now we will create a text file here and.
Here.
The first rope appears inside a set of double quotes so the python interpreter has no trouble executing
and running this command.
So it's okay for now.
However, if you use single quotes.
Python cannot identify where the string should end.
So here we will get an error and this code will not compile because as you can see, we have an error
in line one message.
The python's strength is its diverse community.
Invalid syntax.
And here you will see this error something.
And in the output you can see that error occurs right after the final single quote here.
And this syntax error indicates that the interpreter doesn't recognize something in the code as valid
python code.
Right.
And it thinks the problem might be a string that's not quoted correctly and the errors can.
From a variety of sources, and I will point out some common ones as they arise.
So you might see syntax errors often as you learn to write proper python code.
So syntax errors are also the least specific kinds of errors.
So they can be difficult and frustrating to identify and correct.
So if you get stuck on a particular step or an error, you can ask me and I will answer them immediately.