Lesson 1: Hello, Python! Setup & Your First Program
Installing Python, the REPL, print statements, comments, and why indentation matters.
What is Python?
Python is a general-purpose, high-level programming language created by Guido van Rossum and first released in 1991. It was designed with one guiding philosophy: code should be readable and easy to write. Because Python reads almost like plain English, you can focus on thinking about the problem instead of fighting the syntax. Today Python is the #1 language for beginners, data science, machine learning, artificial intelligence, and web back-ends — which is exactly why this course starts here.
Why Is Python Everywhere in 2026?
- Data Science & AI: Pandas, NumPy, PyTorch, and TensorFlow are all Python-first. If a company trains a model, it is almost certainly written in Python.
- Web Development: Django, FastAPI, and Flask power millions of back-ends.
- Automation & Scripting: Python automates boring tasks — renaming files, scraping websites, cleaning data, and gluing other tools together.
- Education: Its gentle learning curve makes it the default first language in universities worldwide.
- Huge Ecosystem: The Python Package Index (PyPI) hosts over half a million free packages.
Mental model: think of Python as a power tool with a friendly interface — the underlying machinery (C code, memory management) is hidden, so you operate at the level of ideas, not hardware.
What You'll Learn in This Lesson
- Install Python and verify it works on your machine
- Write and run your very first program
- Understand the difference between the REPL and script files
- Master the
print()function and its formatting options - Write comments to document your code
- Understand why indentation is not optional in Python
Installing Python (Step by Step)
- Go to python.org/downloads and download the latest stable version (3.11 or newer). Version 3.12+ is recommended — it is faster and has the newest features.
- Run the installer. Important: tick the checkbox "Add Python to PATH" before clicking Install Now — this lets you run
pythonfrom any terminal. On macOS/Linux you can also install viabrew install pythonor your package manager. - Open a terminal (Command Prompt on Windows, Terminal on macOS/Linux) and verify the installation:
python --version
# Output: Python 3.12.4
If you see a version number, Python is ready. If you see "python is not recognized" or "command not found", you missed the PATH checkbox (Windows) or Python isn't on your PATH (macOS/Linux) — reinstall and tick it, or use python3 on macOS/Linux.
Windows tip: on modern Windows you can also type
pyinstead ofpython— the Python Launcher finds the right version for you.
The REPL vs Script Files
There are two ways to run Python code:
| Method | How to start it | Best for |
|---|---|---|
| REPL (Read-Eval-Print Loop) | Type python in your terminal |
Testing one line at a time, quick experiments |
| Script file | Save a .py file, run python hello.py |
Real programs with many lines |
The REPL reads your input, evaluates it, prints the result, and loops back for more — an instant playground. Script files are how real software is built: you save your code, run the whole file, and share it with others.
Interactive Python in the browser: if you don't want to install anything yet, python.org/shell and replit.com give you a working Python environment in your browser in seconds.
Your First Program
The most famous first program in the world is exactly one line:
print("Hello, world!")
Save it as hello.py and run python hello.py. The output is:
Hello, world!
The print() Function — Your First Tool
print() writes text to the console. Whatever you put inside the parentheses is shown to the user. It has a few powerful options:
| Parameter | What it does | Example |
|---|---|---|
sep |
Separator between multiple values (default is a space) | `print("A", "B", sep=" |
end |
What to print at the end (default is a newline) | print("Hi", end="!") |
file |
Where to write (default is the screen/stdout) | print("log", file=log_file) |
flush |
Force immediate output (default False) |
print("progress", flush=True) |
You can print any number of values in one call, mixing strings and numbers freely:
print("I am", 25, "years old")
print("A", "B", "C", sep=" - ")
print("Line one", end=" | ")
print("still line one")
I am 25 years old
A - B - C
Line one | still line one
Why it matters:
sepandendmight look trivial, but they are the difference between pretty, readable output and a wall of mangled text. Professional scripts use them constantly.
Comments — Notes for Humans
A comment is a note to yourself or other programmers. Python ignores everything after a # on that line:
# This is a comment — Python skips it entirely
print("This runs") # Comments can also go after code
# print("This line is commented out, so it will NOT run")
Comments are how you explain why code exists, not what it does — the code itself shows the what. Good comment habits:
- Comment the why ("we multiply by 1.18 to add 18% GST"), not the obvious what ("this adds two numbers").
- Use comments to temporarily disable code while debugging.
- Keep comments short and current — stale comments mislead worse than none.
- Python also supports multi-line docstrings (
"""...""") for documenting functions and classes — you will use them heavily from Lesson 12 onward.
Indentation is Everything
Most languages group blocks of code with curly braces ({ }). Python uses indentation (spaces or tabs) instead. This is a feature, not a quirk: it forces every programmer to write neatly formatted code.
- A block of code is indented 4 spaces by default (this is the PEP 8 standard).
- Never mix tabs and spaces — it causes an
IndentationError. - Inconsistent indentation is the #1 cause of "my code suddenly broke" for beginners.
if True:
print("Inside the if-block") # 4 spaces
print("Still inside") # same indent = same block
print("Back at top level") # no indent = outside
How to Visualize Code Execution
Imagine Python reading your file top to bottom, one line at a time, like a person following a recipe. Every print() is a "shout" to the console — the order of the shouts is exactly the order of execution. There is no jumping ahead and no skipping lines (until we learn about loops and functions in later lessons).
A beginner debugging ritual: before running code, predict the output by reading line by line out loud. Then run it. If your prediction was wrong, you just found a misunderstanding — and that is a great thing, because now you know exactly what to study.
Understanding Your First Errors
Errors are not failures — they are the interpreter telling you exactly what it needs. The two you will meet first:
| Error | What it means | Example trigger |
|---|---|---|
SyntaxError |
Python could not even read the line — spelling/structure problem | print("Hello (missing closing quote) |
NameError |
You used a name Python has never seen | print(hello) where hello is undefined |
Read the last line of a traceback first — it names the error type and the line number. The huge stack of text above it is context; the punchline is at the bottom.
Common Mistakes to Avoid
- Mistake:
print "Hello"(forgetting parentheses) — Fix:print("Hello"). Python 3 requires parentheses; the old Python 2 syntax no longer works. - Mistake: Mixing tabs and spaces for indentation — Fix: configure your editor to convert tabs to 4 spaces (VS Code: "Editor: Insert Spaces").
- Mistake: Naming a file
print.pyormath.py— Fix: avoid names that collide with Python keywords or built-in modules. - Mistake: Skipping the "Add Python to PATH" checkbox — Fix: reinstall and tick it, or use
py(Windows) /python3(macOS/Linux). - Mistake: Typing
pythoninside the REPL to run a script — Fix: exit the REPL (exit()or Ctrl+Z) first, then runpython hello.py.
Professional Tips & Tricks
- Use 4 spaces for indentation — never mix tabs and spaces.
- Name your files with lowercase letters and underscores:
hello_world.py. - Use
print()freely while learning — it is your flashlight for seeing what code does. - Install a good editor: VS Code (free) with the Python extension gives you syntax highlighting, autocomplete, and one-click run buttons.
- Keep a terminal window open beside your editor — running code every few lines is how you learn fastest.
Key Takeaways
- Python is readable, popular, and the best first language to learn.
- The REPL is for experiments;
.pyscript files are for real programs. print()displays output and supportssep,end,file, andflush.- Comments (
#) document code and are ignored by Python. - Consistent 4-space indentation defines code blocks — and is non-negotiable.
- Errors like
SyntaxErrorandNameErrortell you exactly what to fix — read the last line first.
Next up: Variables, data types, and how Python reads input from the user.
# My very first Python program
print("Hello, world!")
# Print multiple values in one line
print("Amol", "teaches", "Python", 2026)
# print() with a custom separator
print("AI", "ML", "Python", sep=" | ")
# Comments are ignored by Python
# print("This line will NOT run")Lesson Code (Python)
# My very first Python program
print("Hello, world!")
# Print multiple values in one line
print("Amol", "teaches", "Python", 2026)
# print() with a custom separator
print("AI", "ML", "Python", sep=" | ")
# Comments are ignored by Python
# print("This line will NOT run")Console Output
Hello, world!
Amol teaches Python 2026
AI | ML | PythonCode Visualization Tips
- Run this code in your head line-by-line and shout each print() output out loud — the order you shout is the output order.
- Use Python Tutor (pythontutor.com) to see each line light up as it executes.
- Imagine your code as a recipe: Python follows it from the first line to the last, never skipping ahead.
Professional Tips & Tricks
- Use 4 spaces for indentation — never mix tabs and spaces.
- Name your files with lowercase letters and underscores: hello_world.py.
- Use print() freely while learning — it is your flashlight for seeing what code does.
Python Code Judge & Practice Arena
LeetCode StyleRun real Python 3.12 WebAssembly code directly in your browser against automated test suites.
Problem 1: Greeting Formatter 1
Test Your Knowledge
Instant feedbackQuick Check: Lesson 1: Hello, Python! Setup & Your First Program
Up next · Continue learning
Variables, Data Types & Input/Output
The five core data types (int, float, str, bool, None), dynamic typing, type casting, memory references, and reading standard input.