AW Dev Rethought

✂️ Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away - Antoine de Saint-Exupéry

🐍 Python From Zero — 01/13: Your First Python Program


Description:

Your goal today is to save a small Python program and run it. A program is a set of instructions; Python executes those instructions. We’ll use IDLE, the editor and shell available with the standard desktop Python distribution.


1. Install Python

Start at python.org/downloads. Choose the standard supported Python 3 option for your operating system, not an embeddable package or a preview release. If Python 3 already works on your computer, you can use it for this lesson.

Windows: install the official Python install manager. Open Windows Terminal from Start, then enter:

py install default
py --version

The first command installs the manager’s default runtime; the second displays its version. These instructions assume the new install manager; older Python installations may use a legacy py launcher without the install subcommand. See the official Windows setup guide.

macOS: download the standard .pkg installer, open it and follow the prompts. Complete the Install Certificates.command step in the installed Python folder under Applications. Then open Terminal using Spotlight and enter:

python3 --version

A Python 3... response confirms that the command can launch Python. The exact version will vary. See the official macOS setup guide.


. Open the editor

Enter the command for your system in the operating system’s terminal:

Windows macOS
py -m idlelib python3 -m idlelib

IDLE opens a Python Shell window. Choose File → New File to open an editor window. That is where you will write the saved program. Do not copy the shell’s >>> prompt into your file.


3. Write your first instruction

Type this in the new editor:

print("Hello, Python!")
  • print is lowercase and displays output.
  • The matching parentheses contain the value passed to print.
  • The straight quotes mark the text, called a string. The quotes themselves will not appear in this output.

4. Save and run

Choose File → Save As. Create a folder named PythonFromZero somewhere easy to find, such as Documents. Save the file inside it as hello.py.

With the editor active, choose Run → Run Module. IDLE runs the file and displays its output in the Shell window:

Hello, Python!

The shell may also show a restart banner and a >>> prompt. Those belong to IDLE, not to your message. Menu names and appearance can vary slightly by operating system. IDLE documentation.


5. Change it and run again

Add another line:

print("Hello, Python!")
print("I wrote my first program.")

Save, then use Run → Run Module again. Output:

Hello, Python!
I wrote my first program.

The lines run in order. Each print() call adds a newline by default. The downloadable hello.py includes these two lines plus explanatory comments and an opening description.


If something goes wrong

What you see What to check
Command not found / not recognized Finish installation, reopen the terminal, and use the command for your operating system. Follow the official setup troubleshooting guide if needed.
No module named idlelib Your Python distribution may omit IDLE; use the standard desktop distribution or follow your distributor’s IDLE installation instructions.
SyntaxError Compare the line carefully: both straight quotes and both parentheses must be present.
NameError after typing Print Use lowercase print.
File saved as hello.py.txt Save it from the IDLE editor with the .py extension.
Run Module is unavailable Select the editor window, not the Shell window.

Tiny challenge

Change the greeting to include your own name, and change the second message to Python starts here. Save and run again. Try before opening exercise_solution.py.

Write → Save → Run. That is your first repeatable Python workflow.

Next lesson: Variables and Data Types.


Link copied!

Comments

Add Your Comment

Comment Added!