Welcome back.
Let's talk about formatting.
That is code formatting.
A very important tool that comes with a lot of ideas.
And you can also add extensions to code editors like Visual Studio code to format code.
Now, in order for us to talk about that, we have to talk about Python pep.
And if you Google Python pep, you'll get something like this.
Pep stands for Python enhancement proposals.
These are proposals that the community, the Python developer community gives in order for us to have
a standardised way to write code.
And one of the more popular ones if you scroll down.
Is what we call the Pep eight.
You can see that there's a lot of pep numbers.
Well, Pep eight is the most popular one and it's a style guide for Python code.
It tells us this is what good, clean python code should look like.
But luckily for you, you don't have to click through here and read every single thing.
I mean, it is a lot.
Code editors and IDs help us with this.
Let's have a look.
I have a piece of code here in my hello file.
I mean, it doesn't look that bad, but how do we know for formatting the code according to Pep eight?
Well, very easily.
We can run our command palette.
Or we can use a shortcut here.
Command shift P or control shift p if you're on windows and then if we type in format.
Document and click here.
We'll get.
Hey, Formatter, auto pipette is not installed.
Do you want to install it?
And auto pip eight is a popular package with vts code or extension that gives us the pep eight formatter.
So let's install this.
Now let's once again run the format document.
And did you see that?
Our code changed quite a bit.
We have some spaces, some formatting that went on.
And it did that automatically because of Pep eight.
As soon as I change something, let's add some spaces here.
Like that make our code just formatted really strange.
I click save and let's once again command shift V format document.
Now.
Let's save this.
And here Pep eight formatting style was added, for example, with Pep eight.
It recommends that when you write functions that you have two spaces following it.
So two spaces after every function.
Once again, if I remove this and do format document, you see that a space is added because of our
auto pep eight package.
Very, very cool.
And you can also set this up so it does this automatically on save.
I'll leave that one to you to customize your editor and the way that you want.
Now if we go to pie chart.
Pitcher.
Well, again, we have the same code over here.
Just larger text.
Already has this installed for us.
As a matter of fact, you can see the underline here and says Pep eight.
Hey, I expected two blank lines after class or function definition.
So it actually tells you that.
All right, this is not good according to Pep eight.
Or maybe we can add extra space here and right away.
Look at that, Pepe.
Multiple spaces after keyword.
We don't want that.
Now, all we have to do here is simply go to.
Code.
And Reformat Code and you can also see the shortcut available.
If I do this.
Look at that.
The code was reformatted.
Let's make this a little smaller and everything seems to be working.
And I also get a little error.
This is not Pepita.
Again, it's another suggestion by the editor.
Tell me that you've created a new function.
Some, but some actually exists in Python, so you're almost overwriting this again, a really, really
neat feature of Python.
And you know what?
Just because we have a little bit of time just to show you how you can use a VZ code to just save or
format on save.
I can simply go to preferences settings and type in.
Format.
And if I scroll to format on Save, I can click on that.
You can see that changes have been automatically implemented.
So now every time I do command se and save look at that if formats it for me so that we can make sure
that we write clean python code according to the standards.
Let's take a break and I'll see you in the next one.
Bye bye.