Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
In the previous topic, we learned what Python is and where it is used.
Now it is time to prepare our computer so that we can start writing and running Python programs.
For this course, we will use Visual Studio Code (VS Code) as our code editor.
By the end of this lesson, you will be able to:
Visual Studio Code, commonly called VS Code, is a code editor developed by Microsoft.
A code editor is a program where programmers write and manage their code.
Think of it like a notebook for programmers.
Instead of writing Python code on paper, we write it inside VS Code.
VS Code provides several useful features:
Before configuring VS Code, Python itself needs to be installed on your computer.
You can download Python from the official Python website.
Official Python website: https://www.python.org/
On Windows, you may see an option like:
Add Python to PATH
If available, enable this option before starting the installation.
This helps Windows find Python when you run Python commands from the terminal.
Download VS Code from the official website:
https://code.visualstudio.com/
Choose the version for your operating system:
After downloading:
You should now see the VS Code window.
VS Code can support many programming languages.
To make VS Code work nicely with Python, we need to install the Python extension from Microsoft.
After installation, VS Code will have Python-specific features such as:
This is one of the most important steps.
Your computer may have more than one Python installation.
VS Code needs to know:
This selected Python installation is called the Python interpreter.
This opens the Command Palette.
You may see something similar to:
Choose the interpreter you want to use for the course.
Before writing code, it is a good habit to keep your course files organized.
For example, create a folder:
Inside it, you can create folders such as:
This will help you find your programs easily later.
In VS Code:
Python-Beginners folderNow VS Code will treat this folder as your working area.
Let's create our first Python file.
In VS Code:
The .py extension tells us that this is a Python file.
For example:
is a Python file.
.py → Python source fileInside hello.py, write:
Save the file using:
Your file should look like this:
There are different ways to run Python code in VS Code.
For beginners, we will first learn the terminal method.
Go to:
View → Terminal
Or use:
The ` symbol is called a backtick and is usually located near the top-left area of the keyboard.
You should see a terminal appear at the bottom of VS Code.
If your file is called:
type:
Then press Enter.
You should see:
🎉 Congratulations!
You have successfully run your first Python program.
The complete process looks like this:
This basic workflow will become a regular part of your Python learning.
VS Code has many features that can make programming easier.
You don't need to learn everything right now.
Let's understand the most useful ones.
VS Code can suggest code while you type.
For example, when you start writing certain Python functions or objects, VS Code may show suggestions.
This can help you:
VS Code displays different parts of your code using different visual formatting.
For example:
This makes code easier to read.
Sometimes your program does not work as expected.
VS Code provides debugging tools that can help you understand what is happening in your program.
We will learn debugging in more detail later in the course.
The integrated terminal allows you to use command-line tools without leaving VS Code.
For example:
You can run Python programs directly from this terminal.
VS Code supports thousands of extensions.
However, don't install many extensions just because they are available.
Install extensions when you actually need them.
Some useful extensions for Python development include:
Provides core Python development support from Microsoft.
Useful when working with Jupyter Notebooks.
Provides advanced Python language features such as smart code completion, type information, and code analysis.
Provides additional features for working with Git and source control.
VS Code can be customized according to your preferences.
You can change things such as:
You can open Settings using:
However, customization is optional.
You may face a few common problems while setting up Python.
python is not recognizedIf the terminal shows an error when you type:
Python may not be installed correctly or Windows may not know where Python is located.
Check your Python installation and PATH configuration.
Your program may use a different Python version than expected.
Use:
and select:
Then choose the correct Python installation.
Make sure you save your file before running it:
Then run the program again.
Now let's verify that your Python environment is working correctly.
Create a file named:
Add the following code:
Save the file.
Then run:
Don't worry if you don't understand every line yet.
We will learn these concepts later.
For now, understand the purpose:
| Code | Purpose |
|---|---|
sys | Gives information about Python |
platform | Gives information about the computer |
os | Helps work with the operating system |
sys.version | Shows the Python version |
platform.system() | Shows the operating system |
sys.executable | Shows which Python executable is being used |
os.getcwd() | Shows the current working folder |
Your output may look different depending on your computer.
For example:
Before moving to the next lesson, make sure you can check all of these:
.py file can be createdhello.py runs successfullyenv_check.py runs successfullyIf all of these are working, your Python development environment is ready.
In this lesson, you learned:
.py extension.Ctrl + Shift + P opens the Command Palette.Ctrl + S saves your file.Ctrl + ` opens the integrated terminal.hello.py from the terminal?Ctrl + S do in VS Code?In the next lesson, we will continue your Python learning journey with Python Setup (1: Introduction and Setup).
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Python Introduction | Python Setup |
Test your understanding of this lesson with 7 questions. Each question has one correct answer.