Getting started: install, REPL & scripts
Install Python 3.12+, explore the interactive REPL, run your first script and read tracebacks.
Python is designed to be readable. Its syntax looks close to plain English, which makes it a fantastic first language — and it is also a serious professional tool used for web back-ends, automation, data analysis, testing and AI. In this lesson you will install a modern Python (3.12 or newer), meet the interactive REPL, and write and run your first script.
What Python is (and why it is everywhere)#
Python is an interpreted, dynamically typed, general-purpose language:
- Interpreted — you don't compile to a separate executable. The
python3program reads your.pyfile and runs it (internally it compiles to bytecode first, which is why you sometimes see__pycache__folders). - Dynamically typed — you don't declare variable types; values carry their own types.
- Batteries included — the standard library ships with modules for files, dates, JSON, HTTP, databases, testing and much more.
A new Python version is released every October. This course targets Python 3.12+, and everything works on 3.13 too.
Installing Python#
First, check whether you already have it:
If you see 3.12 or newer, you're set. Otherwise install it:
Tip: On Linux and macOS the command is usually
python3, becausepythonmay be missing or point to something else. On Windows it ispyorpython. This course writespython3for commands — use whatever works on your machine.
Do not try to remove or replace the system Python on Linux: the operating system's own tools depend on it. If you need a different version, install it alongside (e.g. with the deadsnakes PPA on Ubuntu, pyenv, or uv python install 3.13).
The REPL — your playground#
Type python3 with no arguments and you drop into the interactive prompt. The >>> is Python waiting for input:
The REPL prints the value of every expression you type, which makes it perfect for quick experiments. Notice the difference: typing "ele" + "phant" + "oo" shows the value with quotes (its representation), while print(...) shows the text itself.
Multi-line statements get a ... continuation prompt; press Enter on an empty line to finish:
Useful REPL tricks:
help(len)shows documentation;dir("text")lists what you can do with a value._holds the last result: type7 * 6, then_ + 1.- Press the Up arrow to recall previous lines.
- Leave with
exit()orCtrl+D(Ctrl+Zthen Enter on Windows).
Python 3.13 introduced a nicer REPL with colours and multi-line editing, but everything above works in 3.12 too.
Your first script#
The REPL forgets everything when you close it. Real programs live in files ending in .py. Create a folder for this course and a file called hello.py in any editor (VS Code with the Python extension is a popular free choice):
Run it from a terminal in the same folder:
Python runs the file top to bottom, one statement at a time. print accepts any number of values, separates them with a space by default, and ends with a newline (the sep and end arguments change that).
You can also run a module by name with -m, which you'll use for tools such as python3 -m venv and python3 -m pip, or run a quick one-liner with -c:
On Linux/macOS you can make a script directly executable by adding a shebang line at the top (#!/usr/bin/env python3) and running chmod +x hello.py; then ./hello.py works.
Indentation is syntax#
In Python, indentation (the spaces at the start of a line) defines structure. This works:
This fails before a single line runs:
The convention (from the PEP 8 style guide) is 4 spaces per level. Configure your editor to insert spaces when you press Tab, and never mix tabs and spaces.
Comments, docstrings and the main pattern#
Python sets the special variable __name__ to "__main__" for the file you run, and to the module's name when a file is imported. That little if is Python's equivalent of a main method — you'll see it at the bottom of almost every real script.
Reading error messages#
Mistakes are normal. Python explains them with a traceback; read it from the bottom up — the last line says what went wrong, the lines above say where:
Here Python refuses to add a number and a piece of text. Modern Python (3.11+) even underlines the exact expression that failed.
Common mistakes#
- Typing shell commands into the REPL (or vice versa).
python3 hello.pygoes in the terminal;print(...)goes in the REPL or a file. If you see>>>, you're inside Python. - Using the wrong Python. If
pythongives "command not found" or an old 2.x version, usepython3. - Smart quotes. Copying code from a word processor can turn
"into“ ”, which Python rejects. Use a code editor. - Saving the file somewhere else.
python3 hello.pylooks in the current folder —cdinto it first, and check withls.
What's next#
You can install Python, experiment in the REPL and run scripts. Next up: variables and data types — how Python stores and labels the values your programs work with.
Check your understanding
Quick quiz
1.What is the REPL?
2.On Ubuntu, which command runs the script
hello.pywith Python 3?3.Why do Python programmers care about indentation?
Finished reading?
Mark this lesson complete to track your progress.