Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:00,750 --> 00:00:07,500
In this lecture I would like to clarify the use of white space so when to use one white space,
1
2
00:00:07,500 --> 00:00:08,940
when to use more than one,
2
3
00:00:08,970 --> 00:00:17,250
and when not to use whitespace, and to explain that to you I've got a script here with three parts.
3
4
00:00:17,250 --> 00:00:20,430
Each of the parts will do the same thing.
4
5
00:00:20,490 --> 00:00:28,470
So the first one prints out a, aa, and three a's, and then b here, and then c.
5
6
00:00:28,560 --> 00:00:35,960
So the first one here I typed in one, two, three, four, five, six. Six spaces.
6
7
00:00:36,090 --> 00:00:37,360
So that will work.
7
8
00:00:37,590 --> 00:00:42,330
As you can see here you get the output correctly but it's not a good practice.
8
9
00:00:42,330 --> 00:00:48,060
Even though that will work it's not a good practice because the code is not very readable.
9
10
00:00:48,060 --> 00:00:52,610
So that's a problem with this first block.
And here in the second block
10
11
00:00:52,620 --> 00:00:56,100
I fixed that so the space here is just right.
11
12
00:00:56,100 --> 00:01:04,790
Basically you you want to separate things with spaces.
When it comes to operators such as the comparison
12
13
00:01:04,790 --> 00:01:08,710
operators or plus or minus or a multiplication
13
14
00:01:08,750 --> 00:01:14,390
the code will work even if you don't have any spaces like that.
14
15
00:01:14,390 --> 00:01:20,890
However to make the code more readable it's better to have some spaces between operators as well.
15
16
00:01:21,140 --> 00:01:25,260
So the space between if and a number is a must.
16
17
00:01:25,400 --> 00:01:28,000
If you have that the code will not work.
17
18
00:01:28,070 --> 00:01:30,440
You will get an invalid syntax.
18
19
00:01:31,070 --> 00:01:41,390
However no space between operators is fine so that's the problem in this block here that you have these expression
19
20
00:01:41,390 --> 00:01:48,110
without spaces, in some particular cases like sometimes I don't use spaces in the videos because I want
20
21
00:01:48,110 --> 00:01:55,550
to show you the text in a greater font so I have to sacrifice with less spaces so that I can fit more
21
22
00:01:55,550 --> 00:01:56,850
text in a screen.
22
23
00:01:56,870 --> 00:02:04,700
So unless you have a good reason to do so please use spaces, one space, and then here that is fine.
23
24
00:02:04,730 --> 00:02:09,830
So one space here, one here, and one there, and then after the colon.
24
25
00:02:09,890 --> 00:02:11,650
So this is what you should know.
25
26
00:02:11,840 --> 00:02:19,040
And I told you already about indentation, after a colon you all this have indentation, indentation means
26
27
00:02:19,430 --> 00:02:21,400
at least one space.
27
28
00:02:21,470 --> 00:02:23,810
So this would also work like that.
28
29
00:02:24,260 --> 00:02:29,340
But a good practice is to have four spaces, four.
29
30
00:02:29,450 --> 00:02:31,710
So that's correct.
30
31
00:02:31,760 --> 00:02:40,200
And when you have more code in your script it's good to separate things with a break line, so to separate logic.
31
32
00:02:40,250 --> 00:02:46,710
So if you have a conditional block there you have to write them line by line no brake lines here
32
33
00:02:46,710 --> 00:02:47,300
like that.
33
34
00:02:47,350 --> 00:02:48,460
That would also work.
34
35
00:02:48,490 --> 00:02:55,150
But please don't use brake lights to make your code more readable however once the conditional block ends,
35
36
00:02:55,150 --> 00:02:57,380
you have another logical block.
36
37
00:02:57,550 --> 00:03:01,580
There's no clear cut rules here but just user logic.
37
38
00:03:01,580 --> 00:03:07,200
So I thought it's good to have these print functions without brake line between them.
38
39
00:03:07,580 --> 00:03:13,730
So here if I would add another function would make a brake line and then create a function here and
39
40
00:03:13,730 --> 00:03:14,850
so on.
40
41
00:03:15,110 --> 00:03:18,150
And of course use indentation for functions as well.
41
42
00:03:18,200 --> 00:03:26,600
So after the colon always comes the indentation, an that's it more or less about spaces whitespace in
42
43
00:03:26,600 --> 00:03:27,020
Python.
4514
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.