1 00:00:00,000 --> 00:00:02,132 In this lecture, I would like to 2 00:00:02,133 --> 00:00:05,156 clarify the use of white space. 3 00:00:05,157 --> 00:00:08,212 So when to use one white space, when to use 4 00:00:08,213 --> 00:00:11,524 more than one, and when not to use white space. 5 00:00:11,525 --> 00:00:13,754 And to explain that to you, I've 6 00:00:13,755 --> 00:00:16,778 got a script here with three parts. 7 00:00:16,779 --> 00:00:20,324 Each of the parts will do the same thing. 8 00:00:20,325 --> 00:00:24,596 So the first one prints a, aa, and three 9 00:00:24,597 --> 00:00:28,492 a's and then b here, and then c. 10 00:00:28,493 --> 00:00:35,954 So the first one here, I typed in 1, 2, 3, 4, 5, 6, 6 spaces. 11 00:00:35,955 --> 00:00:37,356 So that will work. 12 00:00:37,357 --> 00:00:39,068 As you can see here, you get the 13 00:00:39,069 --> 00:00:42,294 outputs correctly, but it's not a good practice. 14 00:00:42,295 --> 00:00:44,912 Even though that will work, it's not a good 15 00:00:44,913 --> 00:00:47,862 practice because the code is not very readable. 16 00:00:47,863 --> 00:00:51,492 So that's a problem with this first block and 17 00:00:51,493 --> 00:00:53,332 here in the second block I fixed that. 18 00:00:53,333 --> 00:00:55,892 So the space here is just right. 19 00:00:55,893 --> 00:00:59,950 Basically, you want to separate things with spaces. 20 00:01:00,610 --> 00:01:05,501 When it comes to operators, such as the comparison operators, 21 00:01:05,502 --> 00:01:09,960 or plus or minus or multiplication, the code will work 22 00:01:09,961 --> 00:01:13,220 even if you don't have any spaces like that. 23 00:01:14,230 --> 00:01:17,436 However, to make the code more readable, it's better 24 00:01:17,437 --> 00:01:20,908 to have some spaces between operators as well. 25 00:01:20,909 --> 00:01:25,276 So the space between if and a number is a must. 26 00:01:25,277 --> 00:01:27,052 If you have that, the code will 27 00:01:27,053 --> 00:01:29,878 not work, you'll get an invalid syntax. 28 00:01:29,879 --> 00:01:33,500 However, no space between operators is fine. 29 00:01:33,501 --> 00:01:35,566 [No audio] 30 00:01:35,566 --> 00:01:38,896 So that's a problem in this block here, 31 00:01:38,897 --> 00:01:42,790 that you have this expression without spaces. 32 00:01:42,791 --> 00:01:46,132 In some particular cases, like sometimes I don't use 33 00:01:46,133 --> 00:01:48,452 spaces in the videos because I want to show 34 00:01:48,453 --> 00:01:51,066 you the text in a greater font. 35 00:01:51,067 --> 00:01:54,548 So I have to sacrifice with less spaces, so 36 00:01:54,549 --> 00:01:56,744 that I can fit more text in the screen. 37 00:01:56,745 --> 00:01:58,216 So unless you have a good reason 38 00:01:58,217 --> 00:02:01,294 to do so, please use spaces, 39 00:02:01,295 --> 00:02:04,520 one space, and then here, that is fine. 40 00:02:04,521 --> 00:02:08,187 So one space here, one here and one there, 41 00:02:08,188 --> 00:02:10,828 then after the colon so this is what you 42 00:02:10,829 --> 00:02:14,418 should know, and I told you already about indentation. 43 00:02:14,419 --> 00:02:17,970 After a colon, you always have indentation. 44 00:02:17,971 --> 00:02:21,360 Indentation means at least one space. 45 00:02:21,361 --> 00:02:24,112 So this would also work like that. 46 00:02:24,113 --> 00:02:29,296 But a good practice is to have four spaces, four. 47 00:02:29,297 --> 00:02:30,640 So that's correct. 48 00:02:31,570 --> 00:02:34,708 And when you have more code in 49 00:02:34,709 --> 00:02:37,396 your script, it's good to separate things 50 00:02:37,397 --> 00:02:40,186 with a break line, separate logics. 51 00:02:40,187 --> 00:02:42,708 So if you have a conditional block there, 52 00:02:42,709 --> 00:02:44,984 you have to write them line by line. 53 00:02:44,985 --> 00:02:47,832 No break lines here like that, that would 54 00:02:47,833 --> 00:02:50,638 also work, but please don't use break lines 55 00:02:50,639 --> 00:02:52,710 to make your code more readable. 56 00:02:52,711 --> 00:02:55,278 However, once the conditional block ends, 57 00:02:55,279 --> 00:02:57,410 you have another logical block. 58 00:02:57,411 --> 00:03:01,426 There's no clear cut rules here, but just user logic. 59 00:03:01,427 --> 00:03:03,756 So I thought it's good to have this 60 00:03:03,757 --> 00:03:07,404 print functions without a break line between them. 61 00:03:07,405 --> 00:03:10,364 So here, if I would add another function, I would make a 62 00:03:10,365 --> 00:03:14,812 break line and then create a function here and so on. 63 00:03:14,813 --> 00:03:18,108 And of course use indentation for functions as well. 64 00:03:18,109 --> 00:03:22,690 So after the colon always comes the indentation 65 00:03:22,691 --> 00:03:25,498 and that's it more or less about spaces, 66 00:03:25,499 --> 00:03:27,200 white space in Python. 67 00:03:27,201 --> 00:03:30,966 [Outro sound]