1 00:00:00,480 --> 00:00:01,620 In programming. 2 00:00:01,620 --> 00:00:10,590 Whitespace refers to any non-printing characters such as spaces, tabs and end of line symbols. 3 00:00:10,590 --> 00:00:15,300 You can use whitespace to organize your output so it's easier for users to read. 4 00:00:15,600 --> 00:00:19,310 To add a tab to your text, use the character t. 5 00:00:20,760 --> 00:00:22,890 Here now we will print. 6 00:00:25,420 --> 00:00:26,880 He Oxley. 7 00:00:27,040 --> 00:00:29,050 Now, we will see this here. 8 00:00:29,050 --> 00:00:31,360 As you can see, we have a tab here. 9 00:00:32,370 --> 00:00:40,830 So let's actually print the Oxley without tab and see how many characters we are seeing now. 10 00:00:41,370 --> 00:00:41,970 Here. 11 00:00:43,440 --> 00:00:45,900 As you can see here, this is accelerated. 12 00:00:46,530 --> 00:00:50,280 This is auxiliary without the tab and this is auxiliary with the tab here. 13 00:00:51,860 --> 00:00:54,050 To add new lines in a string. 14 00:00:54,050 --> 00:00:55,910 You use the character n. 15 00:00:57,790 --> 00:00:58,180 Here. 16 00:00:58,180 --> 00:00:59,710 This is our new line. 17 00:00:59,710 --> 00:01:05,650 So this here is N right here. 18 00:01:08,130 --> 00:01:16,020 And you can also use combine tabs and newlines in a single string. 19 00:01:16,380 --> 00:01:19,320 So now the string here. 20 00:01:19,320 --> 00:01:21,270 Now let's actually end. 21 00:01:22,100 --> 00:01:25,100 T or actually it's pride, right? 22 00:01:25,100 --> 00:01:26,060 The languages. 23 00:01:26,060 --> 00:01:28,400 So languages. 24 00:01:28,940 --> 00:01:32,690 And here we will are Java Python and C plus plus. 25 00:01:32,690 --> 00:01:34,810 So n t. 26 00:01:36,160 --> 00:01:36,880 Python. 27 00:01:39,010 --> 00:01:39,730 Python. 28 00:01:39,730 --> 00:01:41,900 And here n t. 29 00:01:42,910 --> 00:01:45,690 C plus plus and. 30 00:01:48,040 --> 00:01:51,340 C plus plus and T and Java. 31 00:01:52,160 --> 00:01:53,120 Now. 32 00:01:53,880 --> 00:01:55,980 We will see this following output. 33 00:01:57,320 --> 00:01:57,960 That's it. 34 00:01:57,980 --> 00:02:01,480 As you can see here, we have tabs in here. 35 00:02:01,490 --> 00:02:06,890 We have new lines in here, tabs, new lines. 36 00:02:07,540 --> 00:02:08,440 And tabs. 37 00:02:08,890 --> 00:02:14,950 So here actually, it doesn't work like that because as you can see, the first overwrite the new lines 38 00:02:14,950 --> 00:02:18,790 and then tabs, new line tabs, new line tabs. 39 00:02:18,790 --> 00:02:19,930 So it will work. 40 00:02:19,930 --> 00:02:24,580 Firstly, new line here, then tab second. 41 00:02:25,390 --> 00:02:27,640 New Line third EP. 42 00:02:29,090 --> 00:02:33,710 Or new line shift and tab six here. 43 00:02:33,740 --> 00:02:34,760 So that's it. 44 00:02:35,740 --> 00:02:42,700 And the new license tabs will be very useful in the next few sections when you start to produce many 45 00:02:42,700 --> 00:02:45,760 lines of output from just a few lines of code. 46 00:02:45,790 --> 00:02:50,380 Now we can also strip the whitespaces in Python strings. 47 00:02:50,590 --> 00:02:53,680 So let me actually look at the lecture time if we have time. 48 00:02:53,770 --> 00:02:55,990 Yes, just at three minutes now. 49 00:02:55,990 --> 00:03:01,370 So extra whitespace can be confusing for programs programmers. 50 00:03:02,210 --> 00:03:02,920 Python. 51 00:03:03,730 --> 00:03:10,480 The programmers python and here let's actually let's delete this for sorry. 52 00:03:11,350 --> 00:03:14,890 So for programmers python and. 53 00:03:16,210 --> 00:03:18,880 Python look pretty much the same, right? 54 00:03:20,840 --> 00:03:26,300 But to a program they are two different actually. 55 00:03:26,300 --> 00:03:26,470 So. 56 00:03:26,660 --> 00:03:32,330 So so for program they are two different strings. 57 00:03:33,360 --> 00:03:42,570 Python the takes the extra space in second python and considers it significant. 58 00:03:43,340 --> 00:03:45,000 Unless you tell it otherwise. 59 00:03:45,020 --> 00:03:50,750 It's important to think about whitespace because often you will want to compare two strings. 60 00:03:50,750 --> 00:03:52,920 So determine whether they are the same. 61 00:03:52,940 --> 00:03:59,360 For example, one important instance might involve checking people's username when they log into a website. 62 00:03:59,360 --> 00:03:59,750 Right? 63 00:03:59,750 --> 00:04:07,430 So extra whitespace can be confusing in much simpler situations as well. 64 00:04:07,550 --> 00:04:11,300 Version of Python makes it easier to. 65 00:04:12,100 --> 00:04:13,270 Illuminate. 66 00:04:14,140 --> 00:04:18,400 Uh, extra whitespace from data that people enter. 67 00:04:18,670 --> 00:04:26,020 So Python can look at for extra whitespace on the right and the left side of a string. 68 00:04:26,020 --> 00:04:31,120 So to ensure that the whitespace no whitespace exists at the right side of a string. 69 00:04:31,120 --> 00:04:34,690 So you can use our script now. 70 00:04:36,050 --> 00:04:43,130 Uh, my my favorite language here is going to be. 71 00:04:44,790 --> 00:04:45,390 Python. 72 00:04:46,750 --> 00:04:49,210 And here we will use. 73 00:04:50,510 --> 00:04:50,830 Ops. 74 00:04:51,020 --> 00:04:54,800 Let's actually add whitespace here and now. 75 00:04:56,020 --> 00:05:00,520 We will print the my favorite language. 76 00:05:00,520 --> 00:05:04,690 And after that we will use my favorite language. 77 00:05:05,940 --> 00:05:06,420 That. 78 00:05:07,750 --> 00:05:14,290 Strip or strip or strip and that's it that we will print my favorite language. 79 00:05:14,320 --> 00:05:17,260 Language again, my favorite language again. 80 00:05:17,260 --> 00:05:18,610 And after that. 81 00:05:19,620 --> 00:05:20,220 Yeah, that's it. 82 00:05:20,430 --> 00:05:20,970 Yeah. 83 00:05:21,090 --> 00:05:22,440 Now let's run this. 84 00:05:28,560 --> 00:05:32,070 As you can see here, we got to. 85 00:05:32,900 --> 00:05:34,620 Same results. 86 00:05:34,670 --> 00:05:38,750 And here you will see that there is a white space here. 87 00:05:39,820 --> 00:05:44,980 And if you select this like that, you have a white spaces here. 88 00:05:45,770 --> 00:05:56,000 Because you in order to change this or show like this, you will write the script here and now you will 89 00:05:56,000 --> 00:05:57,020 see this here. 90 00:05:57,790 --> 00:06:00,710 Now Python is stripped. 91 00:06:01,150 --> 00:06:07,860 So the value associated with my favorite language contains extra whitespace at the end of a string. 92 00:06:07,870 --> 00:06:13,930 So when you ask Python for this value in a terminal session, you can see the whitespace at the end 93 00:06:13,930 --> 00:06:14,890 of the value. 94 00:06:16,220 --> 00:06:16,730 Right. 95 00:06:17,060 --> 00:06:26,330 So when the answer methods acts on the variable, my favorite language, this extra space is removed, 96 00:06:26,600 --> 00:06:27,950 as you can see here. 97 00:06:30,340 --> 00:06:34,060 However, it's only removed temporarily. 98 00:06:34,180 --> 00:06:43,750 So if you ask for the value of my favorite language, again right here, let's print my favorite language. 99 00:06:44,650 --> 00:06:45,610 The strings. 100 00:06:45,610 --> 00:06:48,280 Look, this looks the same here. 101 00:06:49,100 --> 00:06:49,570 Here. 102 00:06:49,830 --> 00:06:50,570 Here. 103 00:06:51,100 --> 00:06:53,350 So this has whitespace. 104 00:06:53,350 --> 00:06:55,960 This doesn't have whitespace here. 105 00:06:57,020 --> 00:06:59,600 And also this has white space. 106 00:07:00,050 --> 00:07:00,890 So. 107 00:07:01,820 --> 00:07:04,580 As I said, if you ask the value again. 108 00:07:06,610 --> 00:07:11,350 The strings look the same as when it was created, including the extra whitespace. 109 00:07:11,350 --> 00:07:19,270 So to remove the whitespace from the string permanently, you have to associate the script value with 110 00:07:19,270 --> 00:07:20,590 the variable name. 111 00:07:20,770 --> 00:07:21,790 Now. 112 00:07:22,530 --> 00:07:23,370 Let's. 113 00:07:24,980 --> 00:07:25,570 Here. 114 00:07:25,580 --> 00:07:31,460 After that, we will use instead of just writing the variable name like this. 115 00:07:32,800 --> 00:07:34,930 Here writing variable name like this. 116 00:07:34,960 --> 00:07:36,430 We will add this here. 117 00:07:36,970 --> 00:07:42,340 My favorite language equals my favorite language, our script. 118 00:07:42,370 --> 00:07:44,860 Now let's print the value. 119 00:07:44,890 --> 00:07:47,320 Print my favorite language. 120 00:07:50,230 --> 00:07:51,520 And here. 121 00:07:54,370 --> 00:07:55,300 That's it. 122 00:07:55,600 --> 00:07:58,210 So this is firstly the. 123 00:08:00,930 --> 00:08:02,370 White space version. 124 00:08:02,670 --> 00:08:07,560 And this is the version without the white space. 125 00:08:07,890 --> 00:08:12,330 And as you can see, we didn't use the strip function in. 126 00:08:13,450 --> 00:08:15,220 Um, my favorite language. 127 00:08:15,340 --> 00:08:21,370 Because now, after this third line, my favorite language. 128 00:08:22,210 --> 00:08:24,610 My favorite language is. 129 00:08:25,820 --> 00:08:28,250 Value is equal to this. 130 00:08:28,700 --> 00:08:34,610 Whenever you use it, this variable is the name of your my favorite language variable. 131 00:08:35,480 --> 00:08:36,260 So. 132 00:08:37,380 --> 00:08:46,020 In this example, we start with with the value that has whitespace at the beginning and let's actually 133 00:08:46,020 --> 00:08:46,740 yes, yes. 134 00:08:46,740 --> 00:08:53,250 It will be more good practice to use the whitespace on the beginning. 135 00:08:53,250 --> 00:08:53,790 Right. 136 00:08:53,940 --> 00:08:58,300 So now let's add whitespace at the beginning as well. 137 00:08:58,320 --> 00:09:05,610 Now, as you can see here, yes, it would fix our white spaces at the end in the second here because 138 00:09:05,610 --> 00:09:07,620 we don't have the white spaces here. 139 00:09:07,620 --> 00:09:09,480 But I'm sorry. 140 00:09:09,510 --> 00:09:11,280 Here we have white space here. 141 00:09:12,580 --> 00:09:15,580 Button in the start, but not in the end. 142 00:09:15,580 --> 00:09:20,830 So we have white spaces in second in the left, but not on the right. 143 00:09:20,830 --> 00:09:26,560 But here we have white spaces on both sides. 144 00:09:26,920 --> 00:09:33,010 So in order to fix this, we will use our strip here. 145 00:09:34,030 --> 00:09:34,990 So. 146 00:09:36,680 --> 00:09:40,220 Now we will use my favorite language again. 147 00:09:40,220 --> 00:09:43,940 And after that, my favorite language. 148 00:09:43,940 --> 00:09:45,910 That all strip, strip. 149 00:09:46,130 --> 00:09:48,920 Now let's try this out. 150 00:09:49,130 --> 00:09:53,270 And as you can see here, we deleted all the white spaces. 151 00:09:53,270 --> 00:09:59,720 But in the first example that we without manipulation of our text you are seeing here, we have two 152 00:09:59,720 --> 00:10:03,110 white spaces on the left and the right here. 153 00:10:04,460 --> 00:10:09,260 But in the second, we don't have any white spaces here. 154 00:10:09,680 --> 00:10:10,490 That's it. 155 00:10:10,520 --> 00:10:15,590 Because we use these functions are strip and strip.