1 00:00:00,570 --> 00:00:01,710 Narrator: Welcome back. 2 00:00:01,710 --> 00:00:06,207 Let's talk about something called Escape Sequence in Python. 3 00:00:11,550 --> 00:00:15,630 Let's comment this out and let me ask you a question. 4 00:00:15,630 --> 00:00:19,260 What if we wanted to have a string that tells me, 5 00:00:19,260 --> 00:00:23,223 let's say, the weather, and here we wanna write, 6 00:00:24,997 --> 00:00:26,697 "It's sunny". 7 00:00:29,010 --> 00:00:32,820 Hmm. You see how the highlighting changed here? 8 00:00:32,820 --> 00:00:37,140 Because I wanna say it's with an apostrophe s. 9 00:00:37,140 --> 00:00:40,560 But Python is reading this and saying, 10 00:00:40,560 --> 00:00:42,330 okay, this is the start of the string 11 00:00:42,330 --> 00:00:44,010 and this is the end of the string, 12 00:00:44,010 --> 00:00:45,600 and then I have no idea what this is, 13 00:00:45,600 --> 00:00:47,613 and then we're starting a string again. 14 00:00:48,570 --> 00:00:51,000 How can we fix this? 15 00:00:51,000 --> 00:00:55,500 Well, we can add a double quote string instead 16 00:00:55,500 --> 00:00:58,230 and this now works. 17 00:00:58,230 --> 00:01:01,800 But what if for some reason, we also wanted to add, 18 00:01:01,800 --> 00:01:06,800 its kind of sunny, in quotation marks. 19 00:01:07,620 --> 00:01:10,620 Well, now we have another issue. 20 00:01:10,620 --> 00:01:11,850 So how can we solve this? 21 00:01:11,850 --> 00:01:13,980 Because in human language, 22 00:01:13,980 --> 00:01:17,253 we have double quotes and apostrophes. 23 00:01:19,020 --> 00:01:21,513 Well, we can use escape sequences here. 24 00:01:23,070 --> 00:01:25,950 And this is a little hard to understand it first 25 00:01:25,950 --> 00:01:30,950 but it's simply adding a slash like this. 26 00:01:31,020 --> 00:01:34,683 So the one right above your enter on the keyboard. 27 00:01:36,360 --> 00:01:39,330 So this slash, when Python goes through it, 28 00:01:39,330 --> 00:01:41,250 is going to say, all right, 29 00:01:41,250 --> 00:01:44,130 whatever it comes after this, I recognize this symbol. 30 00:01:44,130 --> 00:01:47,493 Whatever comes after this I'm going to assume it's a string. 31 00:01:49,380 --> 00:01:53,550 So now if I do back slash here, 32 00:01:53,550 --> 00:01:56,850 and then back slash here, it's going to say, 33 00:01:56,850 --> 00:02:00,630 hey, Python, I'm letting you know whatever comes after this, 34 00:02:00,630 --> 00:02:01,463 it's a string. 35 00:02:01,463 --> 00:02:04,110 I'm letting you know whatever comes after this is a string 36 00:02:04,110 --> 00:02:05,430 and then I'm letting you know 37 00:02:05,430 --> 00:02:08,100 what comes after this is a string, 38 00:02:08,100 --> 00:02:11,313 so that when we print the weather, 39 00:02:13,470 --> 00:02:16,320 everything is printed nicely. 40 00:02:16,320 --> 00:02:20,970 Awesome. Now this escape sequence, 41 00:02:20,970 --> 00:02:23,220 can be used in multiple ways. 42 00:02:23,220 --> 00:02:26,640 For example, if I wanna have an actual back slash, 43 00:02:26,640 --> 00:02:29,820 well, I can go like this, 44 00:02:29,820 --> 00:02:31,200 and because it's saying 45 00:02:31,200 --> 00:02:33,090 whatever comes after this is a string, 46 00:02:33,090 --> 00:02:35,670 it's going to assume that this is a string now. 47 00:02:35,670 --> 00:02:39,750 So if I run this, you see that we get this backslash. 48 00:02:39,750 --> 00:02:43,320 And there's a few other neat tricks that you can do with it. 49 00:02:43,320 --> 00:02:47,420 For example, one of it is the backslash t. 50 00:02:50,070 --> 00:02:51,840 Hmm. What does that mean? 51 00:02:51,840 --> 00:02:54,480 Well, let's remove this for now. 52 00:02:54,480 --> 00:02:55,313 There you go. 53 00:02:56,610 --> 00:03:00,120 The backs slash t, remember, well, let's add a space in here 54 00:03:00,120 --> 00:03:01,380 so we can distinguish it, 55 00:03:01,380 --> 00:03:02,213 is going to say, 56 00:03:02,213 --> 00:03:04,860 hey, whatever comes after this, 57 00:03:04,860 --> 00:03:06,750 I want you to add a tab. 58 00:03:06,750 --> 00:03:08,910 This is a special meaning here. 59 00:03:08,910 --> 00:03:10,413 So if I click on run, 60 00:03:11,370 --> 00:03:15,633 you see that it's added a tab spacing to my string. 61 00:03:16,980 --> 00:03:21,980 Another one is using n or a new line. 62 00:03:22,140 --> 00:03:26,910 So let's leave t here and then add a back slash n, 63 00:03:26,910 --> 00:03:27,963 and then say, 64 00:03:29,220 --> 00:03:32,163 hope you have a good day. 65 00:03:34,170 --> 00:03:35,730 What do you think will happen here? 66 00:03:35,730 --> 00:03:40,730 If I click run, I have a tab from the back slash t 67 00:03:43,260 --> 00:03:46,560 and then I have a new line after kind of sunny 68 00:03:46,560 --> 00:03:50,580 because I do the back slash n, which denotes a new line. 69 00:03:50,580 --> 00:03:54,150 So that this shows up on a new line. 70 00:03:54,150 --> 00:03:57,510 Now, these escape sequences are hard to see at first 71 00:03:57,510 --> 00:03:59,460 but they're pretty much available, 72 00:03:59,460 --> 00:04:01,860 in all programming languages, that use strings. 73 00:04:01,860 --> 00:04:03,450 So if you come from another language, 74 00:04:03,450 --> 00:04:06,000 this shouldn't be that strange to you. 75 00:04:06,000 --> 00:04:08,070 If it's your first time seeing this 76 00:04:08,070 --> 00:04:10,380 you just need to get used to the syntax 77 00:04:10,380 --> 00:04:13,740 and every once in a while, go to the Python documentation 78 00:04:13,740 --> 00:04:15,750 and just type in escape sequences 79 00:04:15,750 --> 00:04:18,089 and you'll see all the ones that we have. 80 00:04:18,089 --> 00:04:20,390 These are the main ones that you need to know. 81 00:04:21,329 --> 00:04:23,523 All right, more to learn in the next video.