Narrator: Welcome back.
Let's talk about something called Escape Sequence in Python.
Let's comment this out and let me ask you a question.
What if we wanted to have a string that tells me,
let's say, the weather, and here we wanna write,
"It's sunny".
Hmm. You see how the highlighting changed here?
Because I wanna say it's with an apostrophe s.
But Python is reading this and saying,
okay, this is the start of the string
and this is the end of the string,
and then I have no idea what this is,
and then we're starting a string again.
How can we fix this?
Well, we can add a double quote string instead
and this now works.
But what if for some reason, we also wanted to add,
its kind of sunny, in quotation marks.
Well, now we have another issue.
So how can we solve this?
Because in human language,
we have double quotes and apostrophes.
Well, we can use escape sequences here.
And this is a little hard to understand it first
but it's simply adding a slash like this.
So the one right above your enter on the keyboard.
So this slash, when Python goes through it,
is going to say, all right,
whatever it comes after this, I recognize this symbol.
Whatever comes after this I'm going to assume it's a string.
So now if I do back slash here,
and then back slash here, it's going to say,
hey, Python, I'm letting you know whatever comes after this,
it's a string.
I'm letting you know whatever comes after this is a string
and then I'm letting you know
what comes after this is a string,
so that when we print the weather,
everything is printed nicely.
Awesome. Now this escape sequence,
can be used in multiple ways.
For example, if I wanna have an actual back slash,
well, I can go like this,
and because it's saying
whatever comes after this is a string,
it's going to assume that this is a string now.
So if I run this, you see that we get this backslash.
And there's a few other neat tricks that you can do with it.
For example, one of it is the backslash t.
Hmm. What does that mean?
Well, let's remove this for now.
There you go.
The backs slash t, remember, well, let's add a space in here
so we can distinguish it,
is going to say,
hey, whatever comes after this,
I want you to add a tab.
This is a special meaning here.
So if I click on run,
you see that it's added a tab spacing to my string.
Another one is using n or a new line.
So let's leave t here and then add a back slash n,
and then say,
hope you have a good day.
What do you think will happen here?
If I click run, I have a tab from the back slash t
and then I have a new line after kind of sunny
because I do the back slash n, which denotes a new line.
So that this shows up on a new line.
Now, these escape sequences are hard to see at first
but they're pretty much available,
in all programming languages, that use strings.
So if you come from another language,
this shouldn't be that strange to you.
If it's your first time seeing this
you just need to get used to the syntax
and every once in a while, go to the Python documentation
and just type in escape sequences
and you'll see all the ones that we have.
These are the main ones that you need to know.
All right, more to learn in the next video.