KAHIBARO Bookshelves
Discord Login Register

2.3. 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:

  • 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 IDLE or IDLE3, or run idle3 from 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 IDLE

This 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

  1. In IDLE, click File → New 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 File → Save.
    • 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 Run → Run 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:

  • Keywords like if, for, def in 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 syntax

You’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 file
  • Ctrl+N / Cmd+N – New file
  • Ctrl+/ (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:

  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:

  • 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.

  1. Create a folder on your computer, for example: python-projects.
  2. In VS Code, click File → Open 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:

  • 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

  1. Open the terminal inside VS Code:
    • View → Terminal.
  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:

  • 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) or clear (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:

  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:

  • 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

  1. Open IDLE.
  2. File → New 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. File → Open 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: 0

Comments

Please login to add a comment.

Don't have an account? Register now!

Where to Move

Move chapter:

  • ☰ 1. Chapter 1: What Is Programming?
    • ☰ 1.1. What is a computer program?
      • ☰ 1.2. What is Python?
        • ☰ 1.3. Where is Python used?
          • ☰ 1.4. How programming helps solve problems
            • ☰ 1.5. Your first Python program
            • ☰ 2. Chapter 2: Setting Up Python
              • ☰ 2.1. Installing Python (Windows / macOS / Linux)
                • ☰ 2.2. Using Python in the terminal
                  • ☰ 2.3. Using an IDE (IDLE / VS Code)
                    • ☰ 2.4. Running Python scripts
                      • ☰ 2.5. Python interactive mode
                      • ☰ 3. Chapter 3: Variables and Data Types
                        • ☰ 3.1. What is a variable?
                          • ☰ 3.2. Creating variables
                            • ☰ 3.3. Numbers
                              • ☰ 3.4. Test
                                • ☰ 3.5. Boolean values
                                  • ☰ 3.6. Type checking
                                  • ☰ 4. Chapter 4: Basic Operations
                                    • ☰ 4.1. Arithmetic operations
                                      • ☰ 4.2. Working with numbers
                                        • ☰ 4.3. String operations
                                          • ☰ 4.4. Combining text and variables
                                            • ☰ 4.5. Comments in Python
                                            • ☰ 5. Chapter 5: User Input and Output
                                              • ☰ 5.1. Getting input from the user
                                                • ☰ 5.2. Converting input to numbers
                                                  • ☰ 5.3. Formatting output
                                                    • ☰ 5.4. Writing interactive programs
                                                    • ☰ 6. Chapter 6: Conditions
                                                      • ☰ 6.1. Comparison operators
                                                        • ☰ 6.2. Logical operators
                                                          • ☰ 6.3. if, elif, else
                                                            • ☰ 6.4. Nested conditions
                                                              • ☰ 6.5. Common beginner mistakes
                                                              • ☰ 7. Chapter 7: Loops
                                                                • ☰ 7.1. Why loops are useful
                                                                  • ☰ 7.2. for loops
                                                                    • ☰ 7.3. while loops
                                                                      • ☰ 7.4. Loop counters
                                                                        • ☰ 7.5. break and continue
                                                                          • ☰ 7.6. Loop exercises
                                                                          • ☰ 8. Chapter 8: Data Collections
                                                                            • ☰ 8.1. Lists
                                                                              • ☰ 8.2. Tuples
                                                                                • ☰ 8.3. Dictionaries
                                                                                  • ☰ 8.4. Sets (basics)
                                                                                    • ☰ 8.5. Choosing the right data structure
                                                                                    • ☰ 9. Chapter 9: Functions
                                                                                      • ☰ 9.1. Why functions matter
                                                                                        • ☰ 9.2. Defining functions
                                                                                          • ☰ 9.3. Parameters and arguments
                                                                                            • ☰ 9.4. Return values
                                                                                              • ☰ 9.5. Scope (local vs global)
                                                                                                • ☰ 9.6. Reusing code
                                                                                                • ☰ 10. Chapter 10: Working with Files
                                                                                                  • ☰ 10.1. What is a file?
                                                                                                    • ☰ 10.2. Reading text files
                                                                                                      • ☰ 10.3. Writing and appending files
                                                                                                        • ☰ 10.4. File paths
                                                                                                          • ☰ 10.5. Simple file-based programs
                                                                                                          • ☰ 11. Chapter 11: Errors and Debugging
                                                                                                            • ☰ 11.1. Types of errors
                                                                                                              • ☰ 11.2. Reading error messages
                                                                                                                • ☰ 11.3. Common beginner errors
                                                                                                                  • ☰ 11.4. try and except
                                                                                                                    • ☰ 11.5. Debugging strategies
                                                                                                                    • ☰ 12. Chapter 12: Using Python Libraries
                                                                                                                      • ☰ 12.1. What is a library?
                                                                                                                        • ☰ 12.2. Importing modules
                                                                                                                          • ☰ 12.3. Standard libraries
                                                                                                                            • ☰ 12.3.1. math
                                                                                                                              • ☰ 12.3.2. random
                                                                                                                                • ☰ 12.3.3. datetime
                                                                                                                                • ☰ 12.4. Installing external libraries with pip
                                                                                                                                • ☰ 13. Chapter 13: Object-Oriented Programming
                                                                                                                                  • ☰ 13.1. What is object-oriented programming?
                                                                                                                                    • ☰ 13.2. Classes and objects
                                                                                                                                      • ☰ 13.3. The `__init__` method
                                                                                                                                        • ☰ 13.4. Attributes and methods
                                                                                                                                          • ☰ 13.5. Encapsulation
                                                                                                                                            • ☰ 13.6. Inheritance (basics)
                                                                                                                                              • ☰ 13.7. Simple OOP examples
                                                                                                                                              • ☰ 14. Chapter 14: Automation with Python
                                                                                                                                                • ☰ 14.1. What is automation?
                                                                                                                                                  • ☰ 14.2. Automating simple tasks
                                                                                                                                                    • ☰ 14.3. Working with files and folders
                                                                                                                                                      • ☰ 14.4. Automating text processing
                                                                                                                                                        • ☰ 14.5. Scheduling scripts
                                                                                                                                                          • ☰ 14.6. Practical automation examples
                                                                                                                                                          • ☰ 15. Chapter 15: Web Development with Python
                                                                                                                                                            • ☰ 15.1. How the web works (basic overview)
                                                                                                                                                              • ☰ 15.2. Introduction to Flask
                                                                                                                                                                • ☰ 15.3. Creating a simple web server
                                                                                                                                                                  • ☰ 15.4. Routing and templates
                                                                                                                                                                    • ☰ 15.5. Handling user input (forms)
                                                                                                                                                                      • ☰ 15.6. Very basic APIs
                                                                                                                                                                      • ☰ 16. Chapter 16: Data Science with Python
                                                                                                                                                                        • ☰ 16.1. What is data science?
                                                                                                                                                                          • ☰ 16.2. Working with data
                                                                                                                                                                            • ☰ 16.3. Introduction to NumPy
                                                                                                                                                                              • ☰ 16.4. Introduction to pandas
                                                                                                                                                                                • ☰ 16.5. Data visualization with matplotlib
                                                                                                                                                                                  • ☰ 16.6. Simple data analysis examples
                                                                                                                                                                                  • ☰ 17. Chapter 17: Mini Projects
                                                                                                                                                                                    • ☰ 17.1. Number guessing game
                                                                                                                                                                                      • ☰ 17.2. Simple calculator
                                                                                                                                                                                        • ☰ 17.3. To-do list
                                                                                                                                                                                          • ☰ 17.4. Password generator
                                                                                                                                                                                            • ☰ 17.5. Quiz application
                                                                                                                                                                                              • ☰ 17.6. Small web or data project
                                                                                                                                                                                              • ☰ 18. Chapter 18: Next Steps
                                                                                                                                                                                                • ☰ 18.1. How to practice Python
                                                                                                                                                                                                  • ☰ 18.2. Writing clean and readable code
                                                                                                                                                                                                    • ☰ 18.3. Choosing a specialization
                                                                                                                                                                                                      • ☰ 18.3.1. Web development
                                                                                                                                                                                                        • ☰ 18.3.2. Data science
                                                                                                                                                                                                          • ☰ 18.3.3. Automation
                                                                                                                                                                                                            • ☰ 18.3.4. Software development
                                                                                                                                                                                                            • ☰ 18.4. Learning resources and communities
                                                                                                                                                                                                            • ☰ 19. Appendix
                                                                                                                                                                                                              • ☰ 19.1. Python syntax cheat sheet
                                                                                                                                                                                                                • ☰ 19.2. Common errors and solutions
                                                                                                                                                                                                                  • ☰ 19.3. Glossary of terms