Install the below python packages for Python Code Format supporting in Windows
pip install autopep8
pip install pylint
Once you have successfully installed the packages, Open the code in vs code -> Press Ctrl + A and Ctrl + K, it will format the code.
Answer from Dhandapani Sudhakar on Stack OverflowInstall the below python packages for Python Code Format supporting in Windows
pip install autopep8
pip install pylint
Once you have successfully installed the packages, Open the code in vs code -> Press Ctrl + A and Ctrl + K, it will format the code.
autopep8 is listed as a requirement. On mac, using brew, you can install it as follows:
brew install autopep8
Is the python formatting broken in VS Code?
Python Formatting
How can I make VS Code format my Python code? - Stack Overflow
Python Formatter Disapeared
Videos
I am learning python from YouTube. And the Teacher was writing program in VS code. He did two things that didn't happen in my VS code.
Indentation correction. He told that if you give indentation before any variable it will show red. But if you Save it VS code/Pylance will auto correct it.
Imported modules and Libraries will move to the top after saving.
In my case none of the things happened. I have turned every setting on and updated the json file and yet nothing happens. I have also applied settings to all profiles and yet nothing.
Or simply install Black Formatter from VSC extension menu:
https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter

:)
Based on the comments by @starball, @jarmod and additional googling I found that you need to follow those steps:
Step 1. Install Python extension from marketplace: https://marketplace.visualstudio.com/items?itemName=ms-python.python
Step 2. Install one of the formatter packages for Python.
The Python extension supports source code formatting using either autopep8 (the default), black, or yapf.
from and More about it here: https://code.visualstudio.com/docs/python/editing#_formatting
Step 3. Select which code formatter you want to use in python.formatting.provider which is in settings>Extensions>Python (this maybe automatically set after step 1 and step 2). Also, in settings>Extensions>Python there are more options to select.
How to use formatting:
The code formatting is available in Visual Studio Code (VSCode) through the following shortcuts or key combinations:
On Windows Shift + Alt + F
On macOS Shift + Option + F
On Linux Ctrl + Shift + I
Format Selection (Ctrl+K Ctrl+F) - Format the selected text.
Or you can use right click menu:

from: https://mkyong.com/vscode/how-to-format-source-code-in-visual-studio-code-vscode/
and from: https://code.visualstudio.com/docs/editor/codebasics#_formatting