1 00:00:00,460 --> 00:00:01,330 Welcome back. 2 00:00:01,569 --> 00:00:04,600 Let's talk about something called escape. 3 00:00:06,720 --> 00:00:07,650 Sequence. 4 00:00:08,390 --> 00:00:09,500 In Python. 5 00:00:11,480 --> 00:00:15,450 Let's comment this out and let me ask you a question. 6 00:00:15,470 --> 00:00:23,240 What if we wanted to have a string that tells me, let's say, the weather and here we want to write. 7 00:00:25,040 --> 00:00:26,660 It's sunny. 8 00:00:29,070 --> 00:00:29,430 Hmm. 9 00:00:29,910 --> 00:00:32,280 You see how the highlighting changed here? 10 00:00:32,670 --> 00:00:37,650 Because I want to say it's with an apostrophe s, but. 11 00:00:38,460 --> 00:00:43,380 Python is reading this and saying, okay, this is the start of the string and this is the end of the 12 00:00:43,380 --> 00:00:43,920 string. 13 00:00:43,920 --> 00:00:45,570 And then I have no idea what this is. 14 00:00:45,570 --> 00:00:47,640 And then we're starting a string again. 15 00:00:48,470 --> 00:00:50,270 How can we fix this? 16 00:00:50,840 --> 00:00:54,920 Well, we can add a double quote string instead. 17 00:00:55,340 --> 00:00:57,590 And this now works. 18 00:00:58,040 --> 00:01:02,390 But what if for some reason we also wanted to add its. 19 00:01:03,700 --> 00:01:07,330 Kind of sunny in quotation marks. 20 00:01:07,450 --> 00:01:10,120 Well, now we have another issue. 21 00:01:10,510 --> 00:01:11,860 So how can we solve this? 22 00:01:11,860 --> 00:01:17,290 Because in human language, we have double quotes and apostrophes. 23 00:01:18,910 --> 00:01:21,550 Well, we can use escape sequences here. 24 00:01:22,950 --> 00:01:30,210 And this is a little hard to understand at first, but it's simply adding a splash like this. 25 00:01:30,930 --> 00:01:34,710 So the one right above your enter on the keyboard. 26 00:01:36,210 --> 00:01:42,990 So this slash, when Python goes through, it is going to say, all right, whatever comes after this, 27 00:01:42,990 --> 00:01:44,160 I recognize this symbol. 28 00:01:44,160 --> 00:01:47,520 Whatever comes after this, I'm going to assume it's a string. 29 00:01:49,230 --> 00:01:57,360 So now if I do backslash here and then backslash here, it's going to say, hey. 30 00:01:58,090 --> 00:01:58,850 Python. 31 00:01:58,870 --> 00:02:00,640 I'm letting you know whatever comes after this. 32 00:02:00,670 --> 00:02:01,320 It's a string. 33 00:02:01,330 --> 00:02:03,970 I'm letting you know whatever comes after this is a string. 34 00:02:03,970 --> 00:02:06,430 And then I'm letting you know what comes after. 35 00:02:06,430 --> 00:02:07,600 This is a string. 36 00:02:07,930 --> 00:02:11,320 So that when we print the weather. 37 00:02:13,440 --> 00:02:15,750 Everything is printed nicely. 38 00:02:16,290 --> 00:02:16,920 Awesome. 39 00:02:17,910 --> 00:02:22,800 Now this escape sequence can be used in multiple ways. 40 00:02:23,070 --> 00:02:29,790 For example, if I want to have an actual backslash, well, I can go like this. 41 00:02:29,790 --> 00:02:35,070 And because it's saying whatever comes after this is a string, it's going to assume that this is a 42 00:02:35,070 --> 00:02:35,610 string now. 43 00:02:35,610 --> 00:02:42,330 So if I run this, you see that we get this backslash and there's a few other neat tricks that you can 44 00:02:42,330 --> 00:02:43,020 do with it. 45 00:02:43,140 --> 00:02:48,540 For example, one of it is the backslash t. 46 00:02:50,090 --> 00:02:50,490 Hmm. 47 00:02:50,510 --> 00:02:51,650 What does that mean? 48 00:02:51,680 --> 00:02:54,200 Well, let's remove this for now. 49 00:02:54,380 --> 00:02:55,160 There you go. 50 00:02:56,500 --> 00:03:00,970 The backslash t remember, let's add a space in here so we can distinguish. 51 00:03:00,970 --> 00:03:06,730 It is going to say, Hey, whatever comes after this, I want you to add a tab. 52 00:03:06,730 --> 00:03:08,530 This is a special meaning here. 53 00:03:08,740 --> 00:03:10,450 So if I click on Run. 54 00:03:11,260 --> 00:03:11,980 You see that? 55 00:03:11,980 --> 00:03:15,670 It's added a tab spacing to my string. 56 00:03:16,910 --> 00:03:21,710 Another one is using N or a new line. 57 00:03:22,010 --> 00:03:28,010 So let's leave T here and then add a backslash n and then say. 58 00:03:29,260 --> 00:03:32,230 Hope you have a good day. 59 00:03:34,050 --> 00:03:36,690 What do you think will happen here if I click Run? 60 00:03:38,320 --> 00:03:40,030 I have a tab. 61 00:03:40,950 --> 00:03:42,330 From the backslash. 62 00:03:42,330 --> 00:03:49,950 T And then I have a new line after kind of sunny because I do the backslash and which denotes a new 63 00:03:49,950 --> 00:03:53,490 line so that this shows up on a new line. 64 00:03:54,000 --> 00:04:00,270 Now, these escape sequences are hard to see at first, but they're pretty much available in all programming 65 00:04:00,270 --> 00:04:00,750 languages. 66 00:04:00,750 --> 00:04:01,690 They use strings. 67 00:04:01,710 --> 00:04:05,930 So if you come from another language, this shouldn't be that strange to you. 68 00:04:05,940 --> 00:04:11,950 If it's your first time seeing this, you just need to get used to this syntax and every once in a while 69 00:04:11,970 --> 00:04:17,670 go to the Python documentation and just type in escape sequences and you'll see all the ones that we 70 00:04:17,670 --> 00:04:18,079 have. 71 00:04:18,089 --> 00:04:20,310 These are the main ones that you need to know. 72 00:04:21,269 --> 00:04:21,750 All right. 73 00:04:21,750 --> 00:04:23,550 More to learn in the next video.