Introduction
You've probably used a computer to do a hundred things today without once telling it exactly how to do them. Programming is the part where you do tell it, in a language precise enough that a machine can follow it and forgiving enough that a person can learn it. Python is one of the most forgiving languages there is, and this book is the shortest real path from not having it installed to running a script you wrote yourself.
What this book covers
Values and the kinds of things Python works with, naming things, making decisions, repeating work, holding a group of values, packaging logic into functions, using a few tools the language ships with, reading and writing a file, and making sense of an error when one shows up. By the last chapter you'll put all of it into one small script that does something real: keeps track of what you've spent.
This book does not cover classes, decorators, generators, type hints, or third-party packages. Those are real and useful, and they're each a short book of their own elsewhere in this series. The closing chapter says exactly where to find them.
Why Python, if you're choosing
If you're picking a first language rather than being told to use one, Python earns the recommendation honestly. The syntax reads close to plain English, which means less of your early effort goes into fighting punctuation and more goes into the actual ideas: what a loop is, what a function does. It runs the same way on Windows, macOS, and Linux. And it's genuinely used for real work, not just teaching: the same language you're learning here writes web backends, automates spreadsheets, and runs a large share of the tools other programmers reach for. Whatever you end up doing with programming, Python was a reasonable place to have started.
Installing Python
Go to python.org/downloads and get the
current version for your operating system. The installer is standard: run it,
accept the defaults, and on Windows tick the box that adds Python to your
PATH if the installer offers it (it usually does, and it's checked by
default).
Once it's installed, open a terminal. On Windows that's Command Prompt or PowerShell; on macOS or Linux it's Terminal. Type this and press enter:
$ python --version
Python 3.13.0If that prints a version number, you're set. If your terminal says it doesn't
recognize python, try python3 instead, which is what macOS and Linux often
use to keep their own built-in Python separate from the one you installed.
Your version will differ slightly
This book was built and tested on the version printed on the copyright page. A newer patch version (3.13.1, 3.13.2, and so on) is completely fine; nothing here depends on a specific patch release.
If python --version runs but shows something older, like 2.7, that's a
different, much older Python your system had already, and python3 is
almost always the way to reach the one you just installed instead. If
nothing works at all, the most common fix is closing and reopening your
terminal: the installer updates your PATH, the list of places your
terminal looks for a command, but a terminal window already open when you
installed doesn't pick up the change until it's restarted.
The REPL and a script, at a glance
Typing python on its own, with no filename after it, drops you into the
REPL: a prompt that runs one line of code the moment you press enter and
shows you the result immediately. It's a fast way to try something. Chapter 1
uses it properly.
A script is different: it's a plain text file, saved with a .py ending,
that holds a whole sequence of instructions the interpreter reads top to
bottom. That's how you save work and run it again later, and it's what most of
this book builds toward.
Running your first script
Open a text editor, any plain text editor, and save one line into a file
called hello.py:
print("Hello, Python.")
In your terminal, move to the folder where you saved it and run:
$ python hello.py
Hello, Python.print() is a function built into Python that displays whatever you hand it.
You'll use it constantly from here on, starting properly in Chapter 1, where
this same idea is tested for real rather than shown as a transcript.
How the examples in this book work
Most of the code you'll see is run for real while the book is built, and the output printed under it is the actual output, not a guess.
seconds_in_a_day = 24 * 60 * 60
print(seconds_in_a_day)
86400A few examples, like the hello.py one above, are scripts meant for you to
run yourself in your own terminal rather than inside this book's build, mostly
because they wait for you to type something. Those are shown the same way,
as a listing, followed by a sample terminal session so you can see what it
looks like when it runs. Chapter 2 explains exactly why, the first time it
matters.
One more thing worth saying now: type the examples out instead of copying them. Typing them is where the syntax starts to sit in your hands, and breaking one on purpose, on a line you typed yourself, teaches you more than getting it right on the first try.