Previous | Tutorial index | Next
To be able to get Python and Python IDEs running for the learning activities included in this course. Verify Python installation. Set up the chosen IDE. Create a project folder. Write and run a simple script. Explore the interactive interpreter. Configure the IDE with useful extensions. Test the debugger.
In Tutorial 9, you installed Python and an IDE. But having a tool on your computer is not the same as being able to use it effectively. This tutorial bridges the gap between installation and productive coding.
Think of it this way: You have bought a chef's knife and a cutting board (Python and an IDE), but now you need to learn how to hold the knife, set up your workstation, and make your first cut. We will verify everything is working, configure your IDE for maximum efficiency, introduce you to the interactive Python shell (REPL) for experimentation, and finally, teach you how to use a debugger—a tool that will save you countless hours of frustration. By the end of this tutorial, you will be fully prepared to tackle the programming exercises in Unit 2 and beyond.
Before you open an IDE, let's confirm that Python is correctly installed and accessible from your terminal.
Open your terminal (Command Prompt on Windows, Terminal on macOS/Linux) and execute the following command:
python --version
(If that fails, try python3 --version on macOS/Linux, or py --version on Windows).
Expected output: A line like Python 3.12.3 (or a similar 3.x version). This confirms the interpreter is on your PATH.
We will now create a proper .py script and run it. This is the standard way to execute programs.
Open a text editor (like Notepad) or your IDE.
Type the following code:
print("Hello, World!")
Save the file with the name hello.py on your Desktop (or in a dedicated folder). Crucial: Make sure the file extension is .py, not .txt. In Windows, ensure "Save as type" is set to "All Files" to avoid saving hello.py.txt.
Navigate to the folder where you saved hello.py in your terminal:
cd Desktopcd ~/DesktopNow, run the script:
python hello.py
(Or python3 hello.py).
Expected output: Hello, World! printed to the terminal. If you see this, your Python installation is fully functional.
When a program finishes successfully, it returns an exit code of 0 to the operating system. If an error occurs, it returns a non-zero code (e.g., 1). You can check this in your terminal (though you don't need to for basic scripts). This shows that even a simple script communicates with the OS via return codes.
While you can write Python in Notepad, an IDE boosts your productivity exponentially. We will focus on VS Code (recommended), but will also mention PyCharm and Thonny briefly.
File > Open Folder... (or Open on Mac).unit1-projects and select it.Ctrl+N (Cmd+N on Mac). Save it immediately as hello.py (ensure the .py extension is explicit). You will notice syntax highlighting (colors appear for print and the string).Ctrl+Shift+P (Cmd+Shift+P) to open the Command Palette.Python: Select Interpreter and select it.python.exe (Windows) or python3 (Mac/Linux) binary.unit1-projects.venv) for you—a best practice.File > Save As... and save hello.py in your unit1-projects folder.Organizing your files is essential. Untitled folders lead to chaos.
_ instead of spaces.
unit1_projects, homework_1, assignmentUnit 1 Projects (spaces break terminal commands).unit1-projects folder, you can create subfolders for each week or lesson. For now, keep it flat.hello.py here.Python's interactive interpreter is one of its most powerful features for learning and experimentation. It implements a REPL (Read-Eval-Print-Loop).
Open your terminal and type python (or python3) and press Enter. You will see >>> (the primary prompt) or ... (for multi-line statements).
$ python
Python 3.12.3 (tags/v3.12.3:...)
Type "help", "copyright", "credits" or "license" for more information.
>>>
The REPL is perfect for testing small snippets before putting them into a script.
>>> 5 + 3
8
>>> print("Testing!")
Testing!
>>> import math
>>> math.sqrt(16)
4.0
dir() and help()dir(object) shows all the methods and attributes of an object.help(object) prints the documentation for an object.>>> dir("Hello") # Shows string methods (upper, lower, split, etc.)
['__add__', '__class__', '__contains__', ..., 'upper', 'zfill']
>>> help("Hello".upper) # Shows documentation for the upper method
Ctrl + Z then Enter.Ctrl + D.exit() and press Enter.Why use the REPL?
VS Code is minimal out-of-the-box. Extensions add the magic. While you have the Python extension, there are others you should consider.
| Extension Name | Purpose | Why You Need It |
|---|---|---|
| Python (Microsoft) | IntelliSense, linting, debugging, Jupyter notebooks. | The heart of Python support. |
| Pylint or flake8 | Linter (catps syntax errors/style violations). | Highlights errors like missing colons as you type. |
| Python Debugger (Microsoft) | Debugging capabilities (often bundled with Python). | Allows you to set breakpoints and step through code. |
| Jupyter (Microsoft) | Support for .ipynb notebooks. |
Useful for data science and exploratory analysis. |
| indent-rainbow | Colors indentation levels differently. | Prevents "invisible" indentation errors (mixing spaces/tabs). |
| Bracket Pair Colorizer | Colors matching brackets. | Helps track nested parentheses and brackets. |
| Code Runner (Jun Han) | Run code snippets quickly via a button. | Quick execution without using the debugger for simple scripts. |
indent-rainbow.Ctrl+Shift+P), type Python: Select Linter, and choose pylint.Missing whitespace after ',').The debugger allows you to pause execution and inspect variables. This is far more efficient than littering your code with print() statements.
Create a new file debug_test.py in your project folder and write:
def add_numbers(a, b):
result = a + b
return result
x = 10
y = 20
sum = add_numbers(x, y)
print(f"The sum is {sum}")
result = a + b and the line print(f"The sum is {sum}").F5).Once paused, a small toolbar appears at the top of the screen:
While paused, look at the Variables pane on the left:
a: 10, b: 20, result: undefined yet (since you are paused on the line).result appears with the value 30.sum with your mouse—a tooltip shows 30.Why debugging matters: It teaches you how code executes temporally. You see the data flow step-by-step, which is invaluable for understanding complex logic.
Perform the following steps sequentially to prove your setup is 100% operational:
unit1-projects in your terminal.hello.py file (if not done).python hello.py.hello.py file.TERMINAL panel at the bottom.print("Hello, World!").F5 to start debugging.F10 (Step Over) to execute the print.DEBUG CONSOLE panel (not the Terminal).F5 again (Continue) to finish.python.print("Hello from the REPL!").exit() to leave.prin("Hello") (misspelled).NameError: name 'prin' is not defined.If all 5 steps work without errors, your environment is fully configured and ready for the rest of the course!
1. What is the correct command to check your Python version on Windows if python is not recognized?
python --versionpy --versionpython3 --versionpy3 --version2. What does REPL stand for?
3. Which command should you type in a Python interactive session to view all methods of a string object?
help("hello")methods("hello")dir("hello")list("hello")4. When you successfully run a Python script from the terminal, what exit code is typically returned?
1-10True5. In VS Code, how do you select the Python interpreter for your workspace?
Ctrl+Shift+P) and select Python: Select Interpreter6. What is the purpose of a linter (like Pylint) in an IDE?
7. Which extension in VS Code is essential for basic Python support (IntelliSense, linting)?
8. In the VS Code debugger, what does the "Step Over" action (F10) do?
9. If you want to inspect the values of variables inside a function during debugging, which action should you use?
10. Where do debugger outputs (like print statements) appear when you run a script via F5 in VS Code?
TERMINAL tabDEBUG CONSOLE tabInstructions: Open the Python interactive interpreter (REPL) and perform the following tasks. Note down the commands you used and their output.
(25 + 75) * 4 / 2.math module and calculate the square root of 144.my_list = [1, 2, 3]. Use dir() to find a method that adds an item to the end. What is the method name? (Hint: It involves 'append').help() to find out what the math.ceil() function does. Write a one-sentence explanation.Instructions: Write the following Python script in VS Code and save it as buggy.py:
def divide_numbers(x, y):
result = x / y
return result
a = 10
b = 2
c = 0
print("Calculating division...")
d = divide_numbers(a, c) # This will cause a ZeroDivisionError
print(f"Result: {d}")
print("End of program.")
d = divide_numbers(a, c).F5 to start debugging. Step into the function (F11).x and y? What is the value of result before the division?F10 (Step Over) to execute result = x / y. What error appears in the Variables pane or Debug Console? (Write down the error type).y is 0 before dividing).Instructions:
In VS Code, open the Extensions view (Ctrl+Shift+X).
Search for and install the "indent-rainbow" extension.
Create a new Python file named test_indent.py.
Write the following code with incorrect indentation (mix a tab and spaces, or inconsistent levels):
if True:
print("First")
print("Second") # This line has an extra space or tab issue
You should see the indent-rainbow colorizing the indentation differently, making the inconsistency visible. If Pylint is installed, it will underline the invalid indentation.
Write a 2-sentence reflection on why this visual indicator is helpful.
Instructions:
Write the following script path_demo.py:
import os
print("Current working directory:", os.getcwd())
Run from Terminal: Navigate to the folder containing this script in your terminal and run python path_demo.py. Note the output.
Run from VS Code: Open the file in VS Code and click the "Run" button (top right). Note the output.
Question: Are the outputs the same? If not, explain why (Hint: Where is the terminal opened? Where is the IDE's terminal rooted?).
Answer the following questions in complete sentences. Each response should be 3–5 sentences unless otherwise specified.
1. Explain the difference between running a Python script from the terminal (e.g., python my_script.py) and using the "Run" button in an IDE like VS Code. What are the advantages of each approach?
2. What is the primary purpose of the Python interactive interpreter (REPL), and how does it differ from executing a .py file?
3. Why is setting a breakpoint and stepping through code considered a more efficient debugging technique than scattering print() statements throughout your script?
4. The indent-rainbow and Bracket Pair Colorizer extensions were recommended. Why are these particularly useful for a beginner in Python, given Python's reliance on indentation?
Answer the following questions in 300–400 words each.
5. Describe the "workflow" you would use to solve a simple programming problem (e.g., calculating the average of three numbers) using the tools we have set up. Include how you would use the REPL for testing, how you would use the IDE for writing, and how you would use the debugger if you encountered a bug.
Suggested outline:
.py script, and write the main logic.6. Write a troubleshooting guide for a student who has installed Python but cannot get their "Hello, World!" script to run. Address the following scenarios: (a) the terminal says 'python' is not recognized, (b) the script runs but immediately closes (double-click issue), and (c) VS Code reports "No Python interpreter selected."
Suggested outline:
input() to pause.Python: Select Interpreter) and manually locating the interpreter path.These questions require additional research beyond the tutorial content.
7. Research the difference between the Terminal, the Debug Console, and the Output panel in VS Code. Why does print() output sometimes go to the Debug Console and sometimes to the Terminal? (Hint: Look up the difference between the internal console and the integrated terminal).
8. Research the concept of breakpoint conditions in debuggers (e.g., "break only when the loop counter equals 10"). Why are conditional breakpoints more powerful than standard breakpoints in large loops or recursive functions?
9. Explore the interactive features of Jupyter Notebooks (.ipynb). How does a Jupyter Notebook combine the immediate feedback of the REPL with the permanence of a script? Write a short paragraph on why data scientists prefer Jupyter for exploratory data analysis.