How to Format & Indent Your Python Code Automatically in VSCode IDE Using Black Formatter Extension
Jul 8, 2025
Get the full source code of application here:
Show More Show Less View Video Transcript
0:00
Uh hello guys, welcome to this video. So
0:02
in this video, I'll show you a Python
0:04
formatter and indentation character for
0:08
Python files inside VS Code. So if
0:11
you're looking forward for a Python
0:13
formatter, this is a great extension. Go
0:15
to extensions tab and just type here
0:17
black
0:19
formatter.
0:22
So the very first extension which comes,
0:25
you can see it's almost having 5 million
0:27
installs. It's developed by Microsoft.
0:29
It's a verified extension and uh simply
0:32
click the install button and as soon as
0:35
you install this extension you come to
0:37
your Python file and if you make any
0:39
sort of indentation mistake here let's
0:41
suppose this is a valid Python code let
0:44
me make some indentation mistake.
0:53
So now I basically right click and I get
0:56
this option of format document.
1:00
You can actually select your default
1:02
formatter right here. So it's black
1:04
formatter and automatically as soon as
1:06
you click it automatically your Python
1:08
code will be formatted and indentation
1:12
will be corrected. So you can see how
1:14
easy it is. If you have unindented code
1:17
right here can simply format document
1:19
and instantly it will be doing it. So if
1:23
you basically
1:25
for just uh enable this extension, you
1:28
simply add this one property here inside
1:31
your user setting file.
1:34
Just open this uh JSON file and just
1:37
search for this / Python.
1:42
So here specifically we have written for
1:44
Python files here. The formatter will be
1:47
the default formatter will be
1:49
mspython.black black formatter and you
1:51
just need to add one more property so
1:53
that when you save the code here they
1:56
have clearly mentioned this property
1:58
here on their documentation as well
2:00
editor dot format on save. So once you
2:03
actually
2:05
format the code
2:09
by default it's false but we will make
2:11
it true. So now what happens as you
2:15
save your code here
2:18
automatically it the code will be
2:20
formatted.
2:22
So you can add this property here. You
2:23
just need to say control S and
2:25
automatically all your Python code will
2:27
be formatted and indentation will be
2:30
corrected.
2:32
Either you can rightclick format
2:34
document or you can simply say control S
2:37
and all your Python code will be
2:39
formatted. So it's a very useful
2:41
extension. I personally use it a lot
2:44
because in Python code here you may
2:48
sometimes
2:50
just uh the formatting indentation may
2:53
not be correct. So this extension will
2:56
save you a lot of time. Simply press
2:58
Ctrl S and it will format your Python
3:01
code. So this is the extension name
3:03
black format. Simply enable this
3:05
extension and start formatting and
3:07
indentation for your Python files. So
3:11
also check out my website
3:13
freemediattools.com
3:15
uh which contains thousands of tools.
#Programming
#Software
#Scripting Languages
