In this lecture, I would like to
clarify the use of white space.
So when to use one white space, when to use
more than one, and when not to use white space.
And to explain that to you, I've
got a script here with three parts.
Each of the parts will do the same thing.
So the first one prints a, aa, and three
a's and then b here, and then c.
So the first one here, I typed in 1, 2, 3, 4, 5, 6, 6 spaces.
So that will work.
As you can see here, you get the
outputs correctly, but it's not a good practice.
Even though that will work, it's not a good
practice because the code is not very readable.
So that's a problem with this first block and
here in the second block I fixed that.
So the space here is just right.
Basically, you want to separate things with spaces.
When it comes to operators, such as the comparison operators,
or plus or minus or multiplication, the code will work
even if you don't have any spaces like that.
However, to make the code more readable, it's better
to have some spaces between operators as well.
So the space between if and a number is a must.
If you have that, the code will
not work, you'll get an invalid syntax.
However, no space between operators is fine.
[No audio]
So that's a problem in this block here,
that you have this expression without spaces.
In some particular cases, like sometimes I don't use
spaces in the videos because I want to show
you the text in a greater font.
So I have to sacrifice with less spaces, so
that I can fit more text in the screen.
So unless you have a good reason
to do so, please use spaces,
one space, and then here, that is fine.
So one space here, one here and one there,
then after the colon so this is what you
should know, and I told you already about indentation.
After a colon, you always have indentation.
Indentation means at least one space.
So this would also work like that.
But a good practice is to have four spaces, four.
So that's correct.
And when you have more code in
your script, it's good to separate things
with a break line, separate logics.
So if you have a conditional block there,
you have to write them line by line.
No break lines here like that, that would
also work, but please don't use break lines
to make your code more readable.
However, once the conditional block ends,
you have another logical block.
There's no clear cut rules here, but just user logic.
So I thought it's good to have this
print functions without a break line between them.
So here, if I would add another function, I would make a
break line and then create a function here and so on.
And of course use indentation for functions as well.
So after the colon always comes the indentation
and that's it more or less about spaces,
white space in Python.
[Outro sound]