Before writing Python programs, we need two basic tools:
- Python - the programming language and interpreter that executes our Python code.
- 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 World2. 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:
10Think of it this way:
Python Code
↓
Python Interpreter
↓
Computer executes instructions
↓
OutputWithout 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 programs4. Python vs VS Code
Beginners sometimes think Python and VS Code are the same thing.
They are not.
| Python | VS Code |
|---|---|
| Programming language | Code editor |
| Executes Python programs | Helps write programs |
| Provides Python interpreter | Uses Python through an extension/interpreter |
| Required to run Python | Optional but highly recommended |
.py files are Python programs | Opens and edits .py files |
5. Downloading Python
Go to the official Python website:
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:
- Open the Python installer.
- Make sure the option to Add Python to PATH is enabled.
- Click Install Now.
- Wait for the installation to finish.
- 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 PromptThen type:
python --versionYou should see a Python 3 version.
For example:
Python x.x.xThe exact version depends on the version currently installed.
8. Checking the Python Executable
You can also check where Python is installed.
On Windows:
where pythonThis 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:
pythonYou 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 Python10. Exit Python Interactive Mode
To leave the Python interpreter, you can use:
exit()On Windows, you can also press:
Ctrl + Z
Enter11. Installing VS Code
Go to the official Visual Studio Code website:
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 --versionand:
python app.py13. Install the Python Extension
VS Code uses extensions to provide additional programming features.
Open the Extensions section in VS Code.
Search for:
PythonInstall 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_bootcampInside the folder, create:
hello.pyYour project now looks like:
python_bootcamp/
└── hello.py15. 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 TerminalThen run:
python hello.pyOutput:
Hello World17. Run Using the Play Button
VS Code can also provide a Run Python File button.
Open:
hello.pyThen 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 + PSearch for:
Python: Select InterpreterThen 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.13Your VS Code project may need a specific version.
For example:
Project A → Python 3.11
Project B → Python 3.13Selecting 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 Terminalor 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 --versionpython hello.py21. 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_bootcampThen 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.pyTo execute hello.py:
python hello.pyTo execute calculator.py:
python calculator.pyThe general syntax is:
python filename.py23. Python File Naming
Python files normally use:
.pyExamples:
app.py
main.py
calculator.py
student.py
database.pyAvoid unnecessary spaces and confusing names.
Good:
student_data.pyAvoid:
my python file.pyFor 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.pyEach 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 + yThen run the debugger.
The program will pause at that point, allowing you to inspect variables such as:
x = 10
y = 2030. 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 management31. Installing Python Packages
Python has a package manager called pip.
Check pip:
python -m pip --versionYou can install packages using:
python -m pip install package_nameFor example:
python -m pip install requestsThe 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 requestsand:
python -m pip install requestsBoth can work.
For beginners, we recommend:
python -m pip install requestsbecause 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 --versionOn Windows, the Python launcher may be available even when python is not.
34. Problem 2: Wrong Python Version
Check:
python --versionand:
py --listIf multiple versions exist, select the appropriate interpreter in VS Code.
35. Problem 3: VS Code Cannot Find Python
Open:
Ctrl + Shift + PThen search:
Python: Select InterpreterChoose the appropriate Python installation or virtual environment.
36. Problem 4: Code Runs in Terminal but Not in VS Code
Check:
- Is the Python extension installed?
- Is the correct interpreter selected?
- Is the correct project folder open?
- Is the file saved?
- Does the terminal use the expected Python version?
Run:
python --versioninside 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.mdOrganizing 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.pyAdd:
print("Welcome to Python Bootcamp")
name = "Student"
age = 20
print("Name:", name)
print("Age:", age)Run:
python first_program.pyExpected output:
Welcome to Python Bootcamp
Name: Student
Age: 2040. Practice Exercise
Create a file named:
student_profile.pyWrite 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: SkillMantraTry 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 message42. Useful VS Code Shortcuts
| Shortcut | Purpose |
Ctrl + S | Save file |
Ctrl + P | Quickly open a file |
Ctrl + Shift + P | Command Palette |
Ctrl + / | Comment/uncomment |
| `Ctrl + `` | Open/close terminal |
Ctrl + F | Find text |
Ctrl + H | Find and replace |
Ctrl + Z | Undo |
Ctrl + Shift + Z | Redo |
F5 | Start debugging |
Shift + F5 | Stop debugging |