Python

Python Installation & VS Code

Before writing Python programs, we need two basic tools:

  1. Python - the programming language and interpreter that executes our Python code.
  2. Visual Studio Code (VS Code) - a code editor where we can write, manage, and run Python programs.

In this tutorial, we will install Python, configure VS Code, create our first Python file, and learn how to run Python code from both VS Code and the terminal.

1. What is Python?

Python is a high-level, general-purpose programming language known for its simple syntax and wide range of applications.

Python can be used for:

  • Web development
  • Data analysis
  • Data science
  • Machine learning
  • Artificial intelligence
  • Automation
  • API development
  • Desktop applications
  • Scripting
  • Testing
  • Cybersecurity
  • Scientific computing

Python code is executed by the Python interpreter.

For example:

print("Hello World")

When Python executes this program, the output is:

Hello World

2. What is a Python Interpreter?

The Python interpreter is the program responsible for reading and executing Python code.

For example:

x = 10
print(x)

When we run the program, Python interprets these instructions and produces:

10

Think of it this way:

Python Code
     ↓
Python Interpreter
     ↓
Computer executes instructions
     ↓
Output

Without Python installed, your computer does not automatically know how to execute .py files.

3. What is VS Code?

Visual Studio Code (VS Code) is a lightweight source-code editor developed by Microsoft.

It provides features that make programming easier, such as:

  • Syntax highlighting
  • Code completion
  • Error detection
  • Debugging
  • Integrated terminal
  • Extensions
  • File management
  • Git integration
  • Code formatting
  • Multiple programming language support

VS Code itself is not Python.

A useful way to understand the difference is:

Python
→ Executes Python programs

VS Code
→ Helps us write and manage Python programs

4. Python vs VS Code

Beginners sometimes think Python and VS Code are the same thing.

They are not.

PythonVS Code
Programming languageCode editor
Executes Python programsHelps write programs
Provides Python interpreterUses Python through an extension/interpreter
Required to run PythonOptional but highly recommended
.py files are Python programsOpens and edits .py files

5. Downloading Python

Go to the official Python website:

Python.org

Download a current Python 3 release appropriate for your operating system.

For Windows users, download the Windows installer.

6. Installing Python on Windows

After downloading the installer:

  1. Open the Python installer.
  2. Make sure the option to Add Python to PATH is enabled.
  3. Click Install Now.
  4. Wait for the installation to finish.
  5. Close the installer.

Important

The Add Python to PATH option is important because it allows us to run Python commands from the terminal.

The installation screen may look similar to:

+--------------------------------------+
| Python Setup                         |
|                                      |
| ☑ Add python.exe to PATH             |
|                                      |
|        Install Now                   |
|        Customize installation        |
+--------------------------------------+

The exact installer appearance can change between Python versions.

7. Verify Python Installation

After installation, open Command Prompt.

You can open it by:

Windows
→ Search
→ Command Prompt

Then type:

python --version

You should see a Python 3 version.

For example:

Python x.x.x

The exact version depends on the version currently installed.

8. Checking the Python Executable

You can also check where Python is installed.

On Windows:

where python

This displays the location of the Python executable that your terminal is using.

This is useful when multiple Python installations exist on the same computer.

9. Python Interactive Mode

Python can also be used directly from the terminal.

Type:

python

You may see something similar to:

Python x.x.x ...
>>>

The >>> symbol indicates that Python is waiting for your instruction.

Now try:

print("Hello Python")

Output:

Hello Python

10. Exit Python Interactive Mode

To leave the Python interpreter, you can use:

exit()

On Windows, you can also press:

Ctrl + Z
Enter

11. Installing VS Code

Go to the official Visual Studio Code website:

Visual Studio Code

Download the installer for your operating system.

Install VS Code using the normal installation process.

12. Open VS Code

After installation, open Visual Studio Code.

The main interface contains several important areas.

+------------------------------------------------+
| Menu / Command Area                            |
+----------+-------------------------------------+
|          |                                     |
| Explorer |       Code Editor                   |
|          |                                     |
|          |                                     |
|          |                                     |
+----------+-------------------------------------+
|             Integrated Terminal                |
+------------------------------------------------+

The main areas are:

Explorer

Used to manage:

  • Files
  • Folders
  • Projects

Editor

Where you write your code.

Terminal

Where you can run commands such as:

python --version

and:

python app.py

13. Install the Python Extension

VS Code uses extensions to provide additional programming features.

Open the Extensions section in VS Code.

Search for:

Python

Install the official Python extension from Microsoft.

The extension provides features such as:

  • Python syntax support
  • Code completion
  • Debugging
  • Testing support
  • Interpreter selection
  • Error detection
  • Python environment support

14. Create Your First Python Project

Let's create a simple project.

Create a folder:

python_bootcamp

Inside the folder, create:

hello.py

Your project now looks like:

python_bootcamp/
└── hello.py

15. Write Your First Program

Open hello.py and write:

print("Hello World")

Save the file.

The .py extension tells us that this is a Python source-code file.

16. Run Python Code from VS Code

There are several ways to run Python code.

One simple method is to open the terminal in VS Code.

Use:

Terminal
→ New Terminal

Then run:

python hello.py

Output:

Hello World

17. Run Using the Play Button

VS Code can also provide a Run Python File button.

Open:

hello.py

Then click the play/run button near the top-right area of the editor.

VS Code will execute the Python file using the selected Python interpreter.

18. Selecting a Python Interpreter

A computer can have multiple Python versions or environments.

VS Code therefore needs to know which Python interpreter should execute your program.

Open the Command Palette:

Ctrl + Shift + P

Search for:

Python: Select Interpreter

Then select the Python installation or virtual environment you want to use.

19. Why Interpreter Selection Matters

Suppose your computer has:

Python 3.11
Python 3.12
Python 3.13

Your VS Code project may need a specific version.

For example:

Project A → Python 3.11
Project B → Python 3.13

Selecting the correct interpreter ensures that VS Code uses the expected Python environment.

20. Using the Integrated Terminal

VS Code includes a built-in terminal.

Open it using:

Terminal → New Terminal

or use the shortcut:

Ctrl + `

The backtick key is usually located near the Esc key.

You can run commands directly inside this terminal.

For example:

python --version
python hello.py

21. Creating a Python File from Terminal

You can create a project folder and navigate into it from the terminal.

Example:

mkdir python_bootcamp
cd python_bootcamp

Then open the folder in VS Code.

If the code command is available:

code .

The . means:

Open the current directory.

22. Running a Python File

Suppose we have:

python_bootcamp/
├── hello.py
└── calculator.py

To execute hello.py:

python hello.py

To execute calculator.py:

python calculator.py

The general syntax is:

python filename.py

23. Python File Naming

Python files normally use:

.py

Examples:

app.py
main.py
calculator.py
student.py
database.py

Avoid unnecessary spaces and confusing names.

Good:

student_data.py

Avoid:

my python file.py

For larger projects, use clear and meaningful filenames.

24. Creating Multiple Python Files

A project can contain multiple Python files.

Example:

python_bootcamp/
│
├── main.py
├── calculator.py
├── student.py
└── utilities.py

Each file can contain different parts of your application.

Later, we can connect these files using Python modules.

25. Using Comments in VS Code

Python comments start with #.

# This is a comment

print("Hello World")

VS Code can also help you comment and uncomment code quickly.

Select the code and use:

Ctrl + /

This toggles line comments in many VS Code configurations.

26. VS Code Auto Completion

VS Code can suggest code while you type.

For example, type:

student.

VS Code may suggest available methods and attributes.

This feature is called IntelliSense.

It helps developers:

  • Write code faster.
  • Discover available methods.
  • Reduce typing mistakes.
  • Understand APIs.
  • Navigate code more easily.

27. Python Syntax Highlighting

VS Code uses different visual formatting for different parts of Python code.

For example:

name = "Raj"
age = 25

if age >= 18:
    print(name)

Keywords, strings, numbers, functions, and variables can be visually distinguished.

This makes code easier to read.

28. Debugging in VS Code

Debugging means finding and fixing problems in a program.

Suppose:

x = 10
y = 0

result = x / y

print(result)

Running this program produces an error because division by zero is not allowed.

VS Code provides debugging tools that allow us to:

  • Set breakpoints
  • Execute code line by line
  • Inspect variables
  • Watch expressions
  • Understand program flow

We will cover debugging in more detail later in the bootcamp.

29. Breakpoints

A breakpoint tells the debugger:

Pause the program here.

For example:

x = 10
y = 20

result = x + y

print(result)

You can place a breakpoint beside:

result = x + y

Then run the debugger.

The program will pause at that point, allowing you to inspect variables such as:

x = 10
y = 20

30. Python Extension Features

After installing the Python extension, VS Code becomes much more useful for Python development.

Common features include:

Python editing
        ↓
Code completion
        ↓
Linting / diagnostics
        ↓
Debugging
        ↓
Testing
        ↓
Environment management

31. Installing Python Packages

Python has a package manager called pip.

Check pip:

python -m pip --version

You can install packages using:

python -m pip install package_name

For example:

python -m pip install requests

The requests package can be used to make HTTP requests.

We will cover package management in detail later.

32. Why Use python -m pip?

You may see:

pip install requests

and:

python -m pip install requests

Both can work.

For beginners, we recommend:

python -m pip install requests

because it explicitly connects pip to the Python interpreter being invoked.

This can reduce confusion when multiple Python installations exist.

33. Common Installation Problems

Problem 1: python is not recognized

If you see an error similar to:

'python' is not recognized...

Possible causes include:

  • Python is not installed.
  • Python was not added to PATH.
  • The terminal needs to be restarted.
  • Another Python launcher/configuration is being used.

First try:

py --version

On Windows, the Python launcher may be available even when python is not.

34. Problem 2: Wrong Python Version

Check:

python --version

and:

py --list

If multiple versions exist, select the appropriate interpreter in VS Code.

35. Problem 3: VS Code Cannot Find Python

Open:

Ctrl + Shift + P

Then search:

Python: Select Interpreter

Choose the appropriate Python installation or virtual environment.

36. Problem 4: Code Runs in Terminal but Not in VS Code

Check:

  1. Is the Python extension installed?
  2. Is the correct interpreter selected?
  3. Is the correct project folder open?
  4. Is the file saved?
  5. Does the terminal use the expected Python version?

Run:

python --version

inside the VS Code terminal.

37. Recommended Python Project Structure

For beginners:

python_bootcamp/
│
├── 01_basics/
│   ├── hello.py
│   ├── variables.py
│   └── datatypes.py
│
├── 02_strings/
│   └── strings.py
│
├── 03_lists/
│   └── lists.py
│
└── README.md

Organizing lessons this way makes it much easier to find code later.

38. Recommended VS Code Extensions

For a Python Bootcamp, start with only the essential extensions.

Python

Provides Python language support.

Pylance

Provides enhanced Python language features, including intelligent code completion and type information.

Python Debugger

Provides debugging support for Python applications.

Additional extensions can be introduced later depending on the project.

39. First VS Code Exercise

Create:

first_program.py

Add:

print("Welcome to Python Bootcamp")

name = "Student"
age = 20

print("Name:", name)
print("Age:", age)

Run:

python first_program.py

Expected output:

Welcome to Python Bootcamp
Name: Student
Age: 20

40. Practice Exercise

Create a file named:

student_profile.py

Write a Python program that stores:

  • Student name
  • Age
  • Course name
  • Course duration
  • Training institute

Then print the information.

For example:

Student Name: Raj
Age: 22
Course: Python Bootcamp
Duration: 8 Weeks
Institute: SkillMantra

Try creating the program without copying the example exactly.

41. Troubleshooting Checklist

If your Python program does not run, check these in order:

1. Is Python installed?
        ↓
2. Does python --version work?
        ↓
3. Is the Python extension installed?
        ↓
4. Is the correct interpreter selected?
        ↓
5. Is the correct project folder open?
        ↓
6. Is the file saved?
        ↓
7. Are you using the correct filename?
        ↓
8. Check the error message

42. Useful VS Code Shortcuts

ShortcutPurpose
Ctrl + SSave file
Ctrl + PQuickly open a file
Ctrl + Shift + PCommand Palette
Ctrl + /Comment/uncomment
`Ctrl + ``Open/close terminal
Ctrl + FFind text
Ctrl + HFind and replace
Ctrl + ZUndo
Ctrl + Shift + ZRedo
F5Start debugging
Shift + F5Stop debugging

 

Interactive Sandbox
Python