Skip to content

Module 1 · Introduction to Python — topic 10 of 14

Installing Python extensions

Add the official Python extension and Pylance to VS Code, and see how syntax highlighting, autocompletion, error underlines, formatting and debugging help you write correct code.

Beginner 12 min read·Lesson 10 of 306 in Python Programming

Learning objectives

  • Install the Python and Pylance extensions
  • Use autocompletion, hover help and problem underlines
  • Format a file automatically

Definition

Add the official Python extension and Pylance to VS Code, and see how syntax highlighting, autocompletion, error underlines, formatting and debugging help you write correct code.

Introduction

VS Code itself knows little about Python. Extensions add language support. The official Python extension from Microsoft, together with Pylance, turns VS Code into a full Python environment.

Why it matters

These tools catch mistakes before you run the code: a misspelled function name is underlined, missing brackets are highlighted, and hovering over a function shows how to use it. Beginners make fewer frustrating errors with them switched on.

Detailed explanation

Install: open the Extensions view (Ctrl+Shift+X), search for “Python”, and install the extension published by Microsoft. It installs Pylance and the Python Debugger alongside it.

IntelliSense: as you type, suggestions appear. Type pri and press Tab to complete print. Hovering over a name shows its documentation.

Problems: red squiggles mark errors; yellow ones mark warnings. The Problems panel (Ctrl+Shift+M) lists them all.

Formatting: install a formatter such as Black Formatter or Ruff, then use Format Document (Shift+Alt+F) to tidy spacing automatically.

Debugging: the Python Debugger extension lets you pause a program on a line and inspect variables; you will use it in Module 19.

Syntax

Terminal
code --install-extension ms-python.python
  • Extensions can also be installed from the terminal with the code command.
  • ms-python.python is the official Python extension’s identifier.
  • Installing through the Extensions view does exactly the same.

Code examples

Hover over len to read its help

Python
name = "Pylance"
print(len(name))
Output
7

In VS Code, hovering over len shows “Return the number of items in a container.”

Autocompletion on a string

Python
city = "chennai"
print(city.capitalize())
Output
Chennai

After typing city. the editor lists every string method; capitalize is one of them.

More examples

Code the editor would flag, fixed

Python
def area(width, height):
"""Return the area of a rectangle."""
return width * height
print(area(4, 6))
print(area.__doc__)
Output
24
Return the area of a rectangle.

Step-by-step explanation

  • The triple-quoted string under def is a docstring; Pylance shows it when you hover over area anywhere in the file.
  • If you mistyped retrun, the editor would underline it before you ran anything.
  • area.__doc__ prints the same documentation text that the editor displays.

Expected output

Running “Code the editor would flag, fixed” prints exactly:

TextOutput
24
Return the area of a rectangle.

Practical applications

  • Teams enforce one formatter so code reviews focus on logic, not spacing.
  • Type checking in Pylance catches bugs such as passing text where a number is expected.
  • Developers rely on hover documentation instead of switching to a browser constantly.

Best practices

  • Install the official Microsoft Python extension first.
  • Enable format on save once you choose a formatter.
  • Read the hover documentation before searching online.

Common mistakes

Ignoring red underlines

Avoid

Running the file anyway and reading the crash.

Prefer

Hover over the underline and fix it first.

The editor usually tells you the exact problem and line before Python does.

Installing many overlapping extensions

Avoid

Three different Python formatters enabled at once.

Prefer

Use one formatter and set it as the default.

Competing extensions fight over the same file and produce confusing results.

Key takeaways

  • The Python extension adds Pylance, debugging and run support to VS Code.
  • IntelliSense completes names and shows documentation.
  • Squiggles and the Problems panel point out errors early.

Try it yourself

  1. 1
    Install the Python extension, type pri in a new file and complete it to print with Tab.
  2. 2
    Deliberately misspell print as prnt and note the message the editor shows. Then fix it.

Finished reading? Mark it complete to update your dashboard.

Suggested practice

8 questions cover the “Introduction to Python” module. Answers and explanations are revealed after you submit.

  • BeginnerPython is best described as which kind of language?
  • BeginnerWho created Python?
  • BeginnerHow does Python group statements into blocks?
Practise this module