Table of Contents
What Is an IDE?
An IDE (Integrated Development Environment) is a program that helps you write, run, and debug code more easily. It usually includes:
- A code editor (with colors, auto‑indent, etc.)
- A way to run Python
- A place to see output and error messages
- Tools that help you find mistakes
In this chapter, you’ll use two IDEs:
- IDLE – comes with Python, very simple, great for beginners
- Visual Studio Code (VS Code) – more powerful and customizable
You can use either, or both. The core Python you write is the same.
Using IDLE
IDLE is included when you install Python from python.org on Windows and macOS. On many Linux systems, it can be installed via your package manager.
Starting IDLE
How to open IDLE depends on your operating system (OS):
- Windows
- Use the Start menu and search for
IDLE. - You’ll see something like “IDLE (Python 3.x 64‑bit)”.
- macOS
- Open Launchpad or Spotlight and search for
IDLE. - Linux
- Search in your applications for
IDLEorIDLE3, or runidle3from a terminal (if installed).
When IDLE starts, you usually see the Python Shell window.
It looks like this (roughly):
Python 3.x.x (tags/...)
>>>
The >>> is the Python prompt, where you can type Python code.
The Python Shell in IDLE
The Shell lets you run Python code line by line.
For example, type this at the prompt and press Enter:
>>> 2 + 3
5
>>> print("Hello from IDLE")
Hello from IDLEThis is called interactive mode inside IDLE’s Shell.
Use the Shell for:
- Trying small pieces of code
- Quick calculations
- Testing ideas
Creating and Editing a Python File in IDLE
For longer programs, use a file (a script) instead of typing everything in the Shell.
Creating a new file
- In IDLE, click
File→New File. - A new empty window opens. This is the editor window.
- Type some Python code, for example:
# my first script in IDLE
print("Hello from a file!")- Save it:
- Click
File→Save. - Choose a folder.
- Use a name like
hello_idle.py(note the.pyextension).
Running your script in IDLE
To run the file you just saved:
- Make sure the editor window with your code is active.
- Click
Run→Run Module(or pressF5). - The Shell window will appear (or come to front) and show:
>>> ================================ RESTART ================================
>>>
Hello from a file!
>>>Every time you change your code:
- Save (
Ctrl+SorCmd+S). - Run again (
F5).
Basic Features in IDLE for Beginners
You don’t need many features to get started, but a few are helpful.
Syntax highlighting
IDLE automatically colors different parts of your code:
- Keywords like
if,for,defin one color - Strings like
"hello"in another - Comments in another
This helps you see the structure of your code.
Automatic indentation
When you press Enter after a line that starts a block (like after if something:), IDLE will indent the next line for you. This helps keep Python’s indentation rules correct.
Basic error popup
If you make a simple syntax mistake in the editor, IDLE often shows a popup when you try to run:
SyntaxError: invalid syntaxYou’ll see the error details in the Shell as well.
Useful IDLE shortcuts
A few keyboard shortcuts:
F5– Run Module (run the current file)Ctrl+S/Cmd+S– Save fileCtrl+N/Cmd+N– New fileCtrl+/(on some systems) – Toggle comment for selected lines
(Exact shortcuts can vary slightly per OS.)
Using Visual Studio Code (VS Code)
VS Code is a free, popular code editor from Microsoft. With the Python extension, it works very well as a Python IDE.
You should already have installed VS Code and Python in earlier steps; here we focus on using it for Python.
Opening VS Code
- Start VS Code from your Start menu / Launchpad / application list.
- When it opens, you’ll see a welcome screen or an empty window.
You’ll mainly work with:
- The Editor (center) – where you write code.
- The Explorer (left side) – where you see folders and files.
- The Terminal / Output / Problems panel (bottom) – where you see messages.
Installing the Python Extension (One Time)
To make VS Code “understand” Python well, install the official Python extension:
- Click the Extensions icon on the left (it looks like four squares).
- In the search box, type
Python. - Find the extension named “Python” (by Microsoft).
- Click Install.
After this, VS Code will provide Python features like:
- Syntax highlighting
- Code suggestions
- Run/debug support
- Error checking
Opening a Folder for Your Python Projects
VS Code works best when you open a folder that contains your files.
- Create a folder on your computer, for example:
python-projects. - In VS Code, click
File→Open Folder(orOpenon macOS). - Select your
python-projectsfolder. - The folder now appears in the Explorer on the left.
This keeps your project files organized in one place.
Creating a Python File in VS Code
- In the Explorer (left bar), click the New File icon.
- Name your file with a
.pyextension, for example:hello_vscode.py. - Type some code:
# my first script in VS Code
print("Hello from VS Code!")- Save the file (
Ctrl+SorCmd+S).
VS Code should color your code and recognize it as Python.
Selecting the Python Interpreter (One Time per Project)
VS Code needs to know which Python to use (especially if you have more than one version installed).
- Look at the bottom-right corner of VS Code.
- You may see something like
Python 3.x.xor a “Select Python Interpreter” message. - Click there (or press
Ctrl+Shift+P/Cmd+Shift+Pto open the Command Palette and typePython: Select Interpreter). - Choose the Python 3 interpreter you installed (for example, something like
Python 3.x.x 64-bitfrom your main installation path).
Once selected, VS Code will use that Python to run your code.
Running a Python Script in VS Code
There are multiple ways to run your Python file. Two beginner‑friendly methods:
Method 1: Run via the “Run Python File” button
- Open your
hello_vscode.pyfile. - At the top right of the editor, you may see a small “Run” (▶) icon or “Run Python File” text.
- Click it.
VS Code will:
- Open a terminal at the bottom.
- Run something like:
python "c:\path\to\hello_vscode.py"You’ll see the output:
Hello from VS Code!Method 2: Run from the built‑in terminal
- Open the terminal inside VS Code:
View→Terminal.- Make sure the terminal’s current directory is your project folder (VS Code usually handles this).
- Run your script manually:
python hello_vscode.pyOr on some systems:
python3 hello_vscode.pyThe result appears directly in the terminal.
Using the Integrated Terminal
The integrated terminal in VS Code is useful because:
- It opens in the same folder as your project.
- You can run any command (like in your normal system terminal).
- You don’t have to switch between programs.
You can:
- Clear it with
cls(Windows) orclear(macOS/Linux). - Open multiple terminals if needed.
Helpful VS Code Features for Beginners
You don’t need to use everything at once. These simple features are especially helpful:
Syntax highlighting and formatting
VS Code colors your code:
- Keywords like
if,for,def - Strings
- Comments
- Numbers
This makes code easier to read and to spot mistakes.
Code suggestions (IntelliSense)
When you start typing, VS Code often offers suggestions:
- Variable names you’ve already used
- Built‑in functions like
print - Methods and properties of objects
You can:
- Use arrow keys to select a suggestion
- Press Enter or Tab to accept it
This reduces typing and helps you learn names of functions.
Error underlines
If VS Code spots a syntax problem, it may underline code in red or squiggly lines. Hover your mouse over the underline to see a message.
For example, if you forget a closing parenthesis, it may show something like:
“SyntaxError: invalid syntax (missing parenthesis)”
Running parts of your code (via selection)
You can select a line or block of code, right‑click, and look for options like:
Run Selection/Line in Python Terminal
This sends only that part to the Python terminal, useful for quick tests.
Basic debugging (optional, beginner level)
VS Code has powerful debugging tools. A very simple use:
- Click in the left margin next to a line number to set a red dot (a breakpoint).
- Click the Run and Debug icon on the left, then click “Run and Debug” and choose Python (if prompted).
- Your script runs and pauses at that line.
- You can see variable values and step through the code.
This is more advanced, but worth knowing it exists as you progress.
Choosing Between IDLE and VS Code
You can learn Python with either IDLE or VS Code. Use what feels more comfortable.
IDLE advantages:
- Very simple, fewer options
- Comes with Python (no extra setup)
- Good for absolute beginners writing small programs
VS Code advantages:
- Powerful and flexible
- Better for organizing many files and larger projects
- Helpful features like better code suggestions, integrated terminal, and debugging
You can start with IDLE, then move to VS Code when you feel ready, or start directly with VS Code if you’re comfortable with a bit more setup.
Typical Beginner Workflow
Here’s a simple way to work in each IDE.
In IDLE
- Open IDLE.
File→New File.- Write your Python code.
- Save with a
.pyextension. - Press
F5to run. - Check output in the Shell.
- Fix code, save, run again.
In VS Code
- Open VS Code.
File→Open Folderand choose your project folder.- Create a new
.pyfile. - Write your Python code.
- Save.
- Run using the Run button or the integrated terminal.
- Check output and any error messages.
- Fix code, save, run again.
You now know how to use both IDLE and VS Code as your Python IDEs. In later chapters, you’ll write more complex programs using these tools.