Kahibaro
Discord Login Register

Using an IDE (IDLE / VS Code)

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:

In this chapter, you’ll use two IDEs:

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):

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 IDLE

This is called interactive mode inside IDLE’s Shell.

Use the Shell for:

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

  1. In IDLE, click FileNew File.
  2. A new empty window opens. This is the editor window.
  3. Type some Python code, for example:
   # my first script in IDLE
   print("Hello from a file!")
  1. Save it:
    • Click FileSave.
    • Choose a folder.
    • Use a name like hello_idle.py (note the .py extension).

Running your script in IDLE

To run the file you just saved:

  1. Make sure the editor window with your code is active.
  2. Click RunRun Module (or press F5).
  3. The Shell window will appear (or come to front) and show:
   >>> ================================ RESTART ================================
   >>> 
   Hello from a file!
   >>>

Every time you change your code:

  1. Save (Ctrl+S or Cmd+S).
  2. 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:

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 syntax

You’ll see the error details in the Shell as well.

Useful IDLE shortcuts

A few keyboard shortcuts:

(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

You’ll mainly work with:

Installing the Python Extension (One Time)

To make VS Code “understand” Python well, install the official Python extension:

  1. Click the Extensions icon on the left (it looks like four squares).
  2. In the search box, type Python.
  3. Find the extension named “Python” (by Microsoft).
  4. Click Install.

After this, VS Code will provide Python features like:

Opening a Folder for Your Python Projects

VS Code works best when you open a folder that contains your files.

  1. Create a folder on your computer, for example: python-projects.
  2. In VS Code, click FileOpen Folder (or Open on macOS).
  3. Select your python-projects folder.
  4. 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

  1. In the Explorer (left bar), click the New File icon.
  2. Name your file with a .py extension, for example: hello_vscode.py.
  3. Type some code:
   # my first script in VS Code
   print("Hello from VS Code!")
  1. Save the file (Ctrl+S or Cmd+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).

  1. Look at the bottom-right corner of VS Code.
    • You may see something like Python 3.x.x or a “Select Python Interpreter” message.
  2. Click there (or press Ctrl+Shift+P / Cmd+Shift+P to open the Command Palette and type Python: Select Interpreter).
  3. Choose the Python 3 interpreter you installed (for example, something like Python 3.x.x 64-bit from 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

  1. Open your hello_vscode.py file.
  2. At the top right of the editor, you may see a small “Run” (▶) icon or “Run Python File” text.
  3. Click it.

VS Code will:

  python "c:\path\to\hello_vscode.py"

You’ll see the output:

Hello from VS Code!

Method 2: Run from the built‑in terminal

  1. Open the terminal inside VS Code:
    • ViewTerminal.
  2. Make sure the terminal’s current directory is your project folder (VS Code usually handles this).
  3. Run your script manually:
   python hello_vscode.py

Or on some systems:

python3 hello_vscode.py

The result appears directly in the terminal.

Using the Integrated Terminal

The integrated terminal in VS Code is useful because:

You can:

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:

This makes code easier to read and to spot mistakes.

Code suggestions (IntelliSense)

When you start typing, VS Code often offers suggestions:

You can:

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:

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:

  1. Click in the left margin next to a line number to set a red dot (a breakpoint).
  2. Click the Run and Debug icon on the left, then click “Run and Debug” and choose Python (if prompted).
  3. Your script runs and pauses at that line.
  4. 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:

VS Code advantages:

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

  1. Open IDLE.
  2. FileNew File.
  3. Write your Python code.
  4. Save with a .py extension.
  5. Press F5 to run.
  6. Check output in the Shell.
  7. Fix code, save, run again.

In VS Code

  1. Open VS Code.
  2. FileOpen Folder and choose your project folder.
  3. Create a new .py file.
  4. Write your Python code.
  5. Save.
  6. Run using the Run button or the integrated terminal.
  7. Check output and any error messages.
  8. 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.

Views: 18

Comments

Please login to add a comment.

Don't have an account? Register now!