Manual 4 - Getting Started With Python in VSCode
Manual 4 - Getting Started With Python in VSCode
Lab Manual 4
Important Instructions
1. Every student should have lab manual in the lab; otherwise, there will be no
evaluation and attendance.
2. Those students who have Laptop must bring it in the lab fully charged along with
chargers.
3. Students should read the manual before coming to the lab.
4. Every student will have to submit assignments individually and the deadline is the
start of the next Lab session. Assignments after the due date will not be accepted.
Experiment No. 4
Getting started with Python in VSCode
Learning objectives:
• Install Python 3.
• Install and configure Visual Studio Code and extensions on your computer.
• Create a Python file.
• Write and run Python code in Visual Studio Code.
Introduction
The first step to working with any programming language is to set up the necessary tools. Most
developers use a code editor like Visual Studio Code because these tools provide autocomplete for
code and highlight syntax errors. Code editors also provide access to a rich set of add-ons to further
enhance your development experience.
In this lab, you'll set up your Python development environment. You'll use this space to learn Python
and build several applications. You'll also learn how to use Visual Studio Code to create and run a
Python file.
By the end of this lab, you'll have installed the tools required to move forward with your goal of
building applications with Python.
Before you can begin writing Python code, you'll need to install a few tools on your local computer.
You'll need the Python interpreter that compiles and runs your code, and a code editor with features
that can help you write Python code.
Python versions
We try to distinguish between Python version 2 and Python version 3. We make this distinction
because Python 2 was discontinued in 2020. The key idea is that you want to use Python 3 from now
on.
Note: Running python --version or py --version may not return a value or may return an error
message stating 'py' is not recognized as an internal or external command, operable program or batch
file. This indicates Python is not installed on your Windows system.
Install Python 3
1. Download Python 3.13.0 from the Python website, the latest version at this time, and then install
it on your PC.
2. After Python installs, return to the command prompt.
3. Enter the following command python --version and then select Enter to see the version of Python.
To download the Visual Studio Code installer from the Visual Studio Code website:
1. In your browser, navigate to Visual Studio Code download page. The web page displays logos
for Windows, Linux, and Mac.
2. Select and download the Visual Studio Code installer for your system (System Installer).
Most browsers give you the option to either save the file to your local computer (usually in
your Downloads folder) or immediately run the installer file.
Note: After downloading the installer, you may need to open File Explorer and navigate to
the location your web browser downloaded it. The most common location is
the Downloads folder.
3. Double-click the installer file to start the installation process and run through the setup. After
the installation is complete, Visual Studio Code launches automatically.
When Visual Studio Code is installed, you can install the Python extension, and, optionally, set up
other tools and settings. Visual Studio Code is a powerful code editor and a lightweight general-
purpose integrated development environment (IDE) with a wide range of extensions available to
provide functionality in various programming languages. The Python extension for Visual Studio Code
provides visual cues, such as color coding and autocomplete, and debugging tools to help you write
better Python code, and to write code faster. To install the Python extension to your existing VS Code
application, do the following steps.
1. In Visual Studio Code, select View > Extensions to open the Extensions view. The Visual
Studio Code Extensions view lists the installed extensions and recommended extensions from
the most popular on Marketplace.
2. Filter the list of available extensions by entering python in the search box at the top of the
Extensions view.
3. Select the Python extension published by Microsoft (described as IntelliSense (Pylance) and
usually the first one in the list). The details about that extension appear in a tabbed panel on the
right.
If you've successfully installed the above extensions in Visual Studio Code. Let's create our first Python
application!
5. Enter the following Python code in the editor panel. This command uses the print function to
display the text Reg.No._Name when your application is run.
print('Reg.No._Name')
7. Open the built-in terminal in Visual Studio Code by selecting View and Terminal.
8. In the new terminal window, run the following command to run your Python code.
python Lab4.py
a) len
b) print
c) open