 Hey, what's going on guys? Rudolanol here, and today we are looking at some more Python. We're just going to check out some strings. We're going to look at them in a more in-depth way, because they're really interesting. Those strings are the sort of data types that are just like a massive text, or like it's almost like a list of characters. And there are some scenarios though. Because they're denoted by these quotation marks, they can be either a double quotation mark or a single quotation mark. Sometimes we're going to need to break out of those, because what if you were in a situation where you were trying to like, maybe print out dialogue or something. If you wanted to say, John says, hello dog. That hello dog bit should be in quotation marks, because that's just proper. But since you're already inside quotation marks, you would have to break out of them to be able to put more in, which would just cause a problem. So we fixed this with what we call escape characters. So let's get idle started, and I'll show you what I mean. I'll drag this over here, so you guys can see it. And let's get ourself started with a string. I'm going to use that same example I was saying before. John says, hello, Doug. Did I say hello there, Doug? I don't even remember. Let's go for hello there, Doug. So, boom, there we go. Now you can see that our syntax highlighting stopped. And it went back to black text rather than being the green text by default, as if it were a string keyword or that sort of character set. And yeah, we can still get a syntax error that this is invalid syntax. We have just pieces of text just floating around arbitrarily in our command here. So what we do to fix that is we use an escape character. And these are set up by a backslash. So if we go to alt P to bring back our command, what we want to use is a backslash right before that quotation mark here, denoting the dialogue, because that is what's going to start the new text. But when we have that backslash, we have our syntax highlighting is back and everything should be fine because we're taking the literal meaning of this quotation mark. We don't want Python to interpret this as the end of the string. We just want them to interpret as a real string. I'm sorry, a real quotation mark. So we'll have to do the same for that last one because you can see the period over there is still black. And we'll add a little backslash and we'll, there you go. Now it says John says hello there, Doug, perfectly. We have our single quotation marks meaning it's a string. And if we printed this out, we use a little print function here. John says hello there, Doug. So good enough. Now this kind of goes the same way if you're using single quotation marks. So if you were, let's say, he's, oh, I hit the enter key button. Sorry. If we wanted to say he's a dork, he's a dork, I'm a dork. So he's a dork. We still have this single quotation mark. So what you would do here is escape that. And now you're problem solved. Now the thing is with escape characters, though there are sometimes you have special, special escape characters. Like if you backslash n, you can see over here on the left-hand side, backslash n will create a new line. So if we wanted, let's say, this is, I'm going to fix that h right here. This is separated by new lines. Oh, and we're going to have to print that because when Idle returns something, it returns it as the raw string. But print is what's going to understand and understand and interpret. That's the word I'm thinking of. Interpret those new line characters. So this is separate. Oh, I forgot that n there. That's embarrassing. Oh, I also escaped the b. So we'll try that again. Pardon me. We'll try that again. This is separated by new lines. Nice. Nice, nice. This is separate. Oh, I put an extra one. Okay. I'm starting to understand what I'm doing here. So yeah, see now you have all these new line characters that are inputted and there is also a backslash t. So if we print backslash t, backslash t, backslash t, we type in what? What? And now you can see there are all these tab keys, all these tab spaces, and then we have the text that we wanted to display. What? We're using those escape characters and those little sequences there to bring new meaning to what we're displaying. And there are a lot more. There's like a backslash c for a character return, I think. There's backslash r for maybe a line feed. I don't know the exact ones, but backslash n and backslash t are the ones you are most likely going to be using most of the time. So now if, let's go right here. I want to introduce you to the single backslash, because in case you ever do need to print out a backslash, self becomes a problem because backslash is the character to represent an escape character. So we would have to print backslash, backslash, backslash, backslash. And now we have a single backslash, because it's interpreting it as the real backslash. I know that's a little hard to wrap your head around, and it's a lot of the same. Like I'm saying backslash over and over again escape character, but these mean different things, but they mean something that makes sense. Backslash n and new line. Backslash t tab. So now another interesting thing that Python has is called a raw string, and this is understanding it in a different way. If we print out, let's say John says hello there, and that works perfectly fine. Actually it doesn't, because we'd have to use those backslashes here. Let's get a backslash right over there, and another one right at the end of that string. John says hello there. What you could do is put an R in front of there, and it's going to use that as a raw string. So whatever is in that string, it's going to interpret it the way it should. So that backslash is going to be included as a real backslash. I'm curious if we tried it again without those, if we actually... Nope. That's not gonna work. But it is interpreting that first one. So that's interesting. If we cut that one out. Yep. But that's kind of what I'm trying to get at here. The raw string in the previous example that I was showing you, that R in front of a string is going to represent what that string really means. So if you use those two backslashes again, it's going to print out backslash, backslash, backslash, because you have 1, 2, 1, 2. So you're using real backslashes, and a backslash is supposed to mean two backslashes. When you have two backslashes, it's really 1 when it's raw. But if we did that in print, you get those. So that might be a little tough to wrap your mind around, but especially in those examples, I really didn't do that great of a job explaining it, but I'm sure if you look at other examples and what other people have done, there are other strings that might be a little bit more complex, and you're going to be able to understand that, though, by knowing these escape characters and these escape sequences and the other things that you might need to understand while you're programming. So actually with print, though, print automatically adds a new line every time you output something, so you don't have to have that backslash N at the end of it. So if I said hello, you can see there's an extra one there, but if I just did hello, it's perfectly fine. So print automatically ends the backslash N, or at least it creates a new line. But yeah, that's kind of all I wanted to show you guys today. Escape characters are a little bit interesting, but they can definitely make your life a lot easier when you're working with strings, so I recommend you check them out and give them a go. But thank you for watching, guys. Thanks for listening, and I'll see you again in the next tutorial.