VS Code includes support right out of the box for popular programming
languages like JavaScript, TypeScript, HTML,
and CSS,
but you can add support for just about any programming language you
can imagine with extensions.
I'm going to demonstrate adding support for the Python
programming language, but the process will be similar
for other languages.
The code for my website here doesn't currently have any
Python files in it,
but I'm going to add one now and just name it hello.py.
Py is the standard file extension for Python code files.
As soon as the new file is created,
notice that I get a message at the bottom of the screen asking me if
I want to install the recommended Python extension.
That's a helpful suggestion and probably the quickest way to
install the extension, but I'm going to close that and
show you a couple more things before I manually install it.
I'm going to paste some very simple Python code
into my new file.
This declares a simple function at the top to add two numbers.
I then declare a couple of variables and pass them
to the function.
Finally, it prints a line of output stating the two numbers
that were added and the sum returned from the function.
Even without the Python extension installed,
I'm getting some decent syntax highlighting.
However, there's not much else I can do with this file currently.
I'll press "Ctrl Shift P" to open the command palette.
I'll then search for Python.
The command palette found no matching commands.
I have no way to run or debug the code from inside VS Code.
I'll now click the extensions icon on the activity bar.
Under the list of recommended extensions,
the first item is the Python extension developed by Microsoft.
I'll click on it to view the detail page for it.
It's obviously very popular with well over 100 million downloads.
This page includes lots of useful information such as the
steps to get started, setting up your environment,
and how to run useful commands.
One very important point I want to make about this extension is that
it does not include a Python interpreter.
You'll need to install that yourself as you would before doing
any Python development.
I'll go ahead and install the extension by clicking the blue
install button near the top.
After a couple of seconds, the extension is installed and it
now appears in my list of installed extensions on the left.
Some extensions have dependencies which will automatically
get installed.
That's the case here.
Just below the Python extension, you can see that an extension
named Pylance was also installed.
It's a language server for using Python in VS Code.
I'll close the extension page to return to our Python code.
With the extension installed, I'll open the command palette
again and search for Python.
This time, the search reveals lots of Python-related commands
I can now run inside VS Code.
The first in the list lets me select which installed interpreter
I want to use.
There are also commands for lots of other things like
configuring test,
debugging code, and lots more.
In addition to the commands added to the command palette,
there's also a new button added to the upper right corner of the
window when you have a Python code file open.
I'll click the dropdown arrow beside it and you can see I have
options to run and debug my Python file.
I'll click in the left margin of my code file to set a breakpoint
on Line 5.
I'll click the dropdown arrow again and select "Debug
Python File."
That uses the installed Python interpreter to begin running the
program in the debugger.
It opens a new terminal below, and execution quickly
pauses on Line 5 where I set my breakpoint.
From here, I have access to debugging features you're probably
familiar with from other environments.
I can use the buttons at the top of the window to step
into or over code.
On the left side of the screen are sections where you can view the
value of local variables, configure watch expressions,
and view the call stack.
I'll quickly add a watch expression for the sum variable.
I can stop the debugger by pressing the red square on the
debug toolbar at the top.
That's a quick preview of how to get started with the
Python extension,
but there are lots of other languages available.
I'll click on the extensions icon again.
I'll then click on the "Filter" button to the right of the
search box at the top.
From there, I'll select "Category" and "Programming Languages"
from the menus.
That brings up a long list of extensions for many different
programming languages, and is a great way to browse
what's available.
Extensions make it possible for you to use VS Code and be
productive with it no matter the language
you're using.
Up next, I'll show you how extensions can also be used to add
additional functionality to your editor,
regardless of the language you use.