CHAPTER 3Editing Code
Visual Studio Code provides a number of standard editing features that work for all programming languages.
- Quick Fixes
- Code completion
- Definitions
- Declarations
- Formatting
- Linting
- Refactoring
- Code snippets
These built-in editing features save time by reducing the number of manual tasks and typing that might usually be necessary to edit code.
The Python extension extends the functionality of the code editing features by providing Python-specific support. With the Python extension, importing libraries requires minimal effort, as the extension can suggest installed packages to import into a program. More often, after just a few typed characters, the editor can auto-complete lines of code, provide definitions, and even locate declarations.
Whether you prefer autopep8, Black, or YAPF, you can set your desired formatter and customize the settings to ensure that the source code is formatted to your liking. As you run your Python code, linting analyzes how the code runs and outputs errors in the Problems panel. If you find the need to refactor a Python program, commands are available to extract variables, methods, and sort imports. Furthermore, you could save time using code snippets to avoid manually entering repeating code patterns.
In this chapter, each editing feature is explored in a script named circle_area.py
that uses the math
module to calculate the area of a circle. Before trying the examples in this chapter, create a new Python file called circle_area.py ...
Get Visual Studio Code for Python Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.