Write and Run Hello World Without an Editor
Introduction
This chapter shows you how to write and run a Python hello_world program without using any code editor. You will complete everything in the terminal, including file creation, execution, and quick troubleshooting. This matters because terminal-first workflows are common in servers, containers, and remote environments.
Prerequisites
- Python
3.10+installed (3.12recommended) - Basic command-line knowledge (
cd,ls, creating files) - A terminal environment:
- Windows: PowerShell or Command Prompt
- macOS/Linux: Terminal (zsh/bash)
Why Learn Terminal-Only Hello World
A no-editor workflow teaches core runtime fundamentals. It also helps you debug quickly when GUI tools are unavailable.
Core benefits:
- Verify Python installation in a minimal environment
- Build confidence with command-line operations
- Practice reproducible steps for servers and CI jobs
Tip
Best Practice
Keep terminal commands simple and explicit when teaching or documenting beginner flows.
Step 1: Verify Python in Terminal
Before writing the file, confirm that Python is available.
# Check Python version
python3 --versionOn Windows, if python3 does not work:
# Check Python version with Windows launcher
py --versionStep 2: Create hello_world.py Without an Editor
Use shell redirection to create the script directly from terminal input.
macOS / Linux
# Create hello_world.py with one print statement
printf 'print("Hello, World!")\n' > hello_world.pyWindows PowerShell
# Create hello_world.py with one print statement
Set-Content -Path .\hello_world.py -Value 'print("Hello, World!")'Windows Command Prompt
:: Create hello_world.py with one print statement
echo print("Hello, World!") > hello_world.pyWarning
Do not use rich-text tools (for example, Word or chat copy with smart quotes) to create .py files. Hidden characters can break execution.
In Python, running your first program only requires one line of code.This demonstrates Python’s core philosophy of simplicity.
# This is a comment: The following line prints text to the screen
print("Hello, World!")Breakdown of the Code
-
print(): This is a Python built-in function.Its function is to output the information within the brackets to the console (Terminal/Console). -
"Hello, World!": This is a string.In Python, text must be wrapped in double quotes " or single quotes ' otherwise the interpreter will mistake it for a variable or command. -
# (Comments): Lines starting with a pound sign are comments.They are not executed and are only read by developers to explain the logic of the code.
Step 3: Run the Script
Execute the script from the same directory where the file was created.
# Run hello_world.py with Python 3
python3 hello_world.pyOn Windows, this command is also common:
# Run hello_world.py with Python launcher
py hello_world.pyExpected output:
Hello, World!
Optional Step: Run with a Virtual Environment
Even for small scripts, using a virtual environment builds good habits.
# Create a local virtual environment
python3 -m venv .venv
# Activate virtual environment on macOS/Linux
source .venv/bin/activate
# Run script with local interpreter
python hello_world.pyFAQ
Can I learn Python without an editor at first?
Yes. Terminal-only practice is a great way to learn execution basics, file paths, and environment handling. You can add an editor later without losing this foundation.
Why do some systems use python3 while others use py?
python3 is common on macOS/Linux. On Windows, py is the Python Launcher and can select installed versions more reliably.
What is the minimum program to test Python?
A single line is enough:
print("Hello, World!")
Should I still use a virtual environment for tiny scripts?
For one-off experiments it is optional, but for anything you keep or share, virtual environments are strongly recommended.