Skip to content
elephantoo

Getting started: install, REPL & scripts

Lesson 1 of 38 15 min read

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 python3 program reads your .py file 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:

Terminal
python3 --version
Output
Python 3.12.3

If you see 3.12 or newer, you're set. Otherwise install it:

Terminal
# Ubuntu 24.04+ / Debian 13+ (Python 3.12+ is the default)
sudo apt update
sudo apt install python3 python3-pip python3-venv

# Fedora (ships a recent Python out of the box)
sudo dnf install python3 python3-pip

# macOS (Homebrew)
brew install python

# Windows: download the installer from https://www.python.org/downloads/
# tick "Add python.exe to PATH", then use `py` or `python` in the terminal

Tip: On Linux and macOS the command is usually python3, because python may be missing or point to something else. On Windows it is py or python. This course writes python3 for 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:

Output
>>> 2 + 2
4
>>> "ele" + "phant" + "oo"
'elephantoo'
>>> print("Hello, Elephantoo!")
Hello, Elephantoo!
>>> len("Python")
6

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:

Output
>>> for n in range(3):
...     print(n * 10)
...
0
10
20

Useful REPL tricks:

  • help(len) shows documentation; dir("text") lists what you can do with a value.
  • _ holds the last result: type 7 * 6, then _ + 1.
  • Press the Up arrow to recall previous lines.
  • Leave with exit() or Ctrl+D (Ctrl+Z then 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):

hello.py
print("Hello, Elephantoo!")
print("2 + 2 is", 2 + 2)
print("Python makes", "this", "easy", sep=" ~ ")

Run it from a terminal in the same folder:

Terminal
python3 hello.py
Output
Hello, Elephantoo!
2 + 2 is 4
Python makes ~ this ~ easy

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:

Terminal
python3 -c "print(10 ** 3)"
Output
1000

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:

Python
if True:
    print("yes")
    print("still yes")
print("always runs")
Output
yes
still yes
always runs

This fails before a single line runs:

Python
if True:
print("oops")   # not indented — Python rejects it
Output
IndentationError: expected an indented block after 'if' statement on line 1

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#

greet.py
# A comment starts with # and runs to the end of the line.

"""
A string on its own at the top of a file is the module's docstring.
Tools like help() display it.
"""


def greet(name):
    """Return a friendly greeting."""  # a function docstring
    return f"Hi, {name}!"


# Only run this when the file is executed directly,
# not when another file imports it:
if __name__ == "__main__":
    print(greet("friend"))
Output
Hi, friend!

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:

Python
print("Total:", 10 + "5")
Output
Traceback (most recent call last):
  File "demo.py", line 1, in <module>
    print("Total:", 10 + "5")
                    ~~~^~~~~
TypeError: unsupported operand type(s) for +: 'int' and 'str'

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.py goes in the terminal; print(...) goes in the REPL or a file. If you see >>>, you're inside Python.
  • Using the wrong Python. If python gives "command not found" or an old 2.x version, use python3.
  • 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.py looks in the current folder — cd into it first, and check with ls.

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

0/3 answered
  1. 1.What is the REPL?

  2. 2.On Ubuntu, which command runs the script hello.py with Python 3?

  3. 3.Why do Python programmers care about indentation?

Finished reading?

Mark this lesson complete to track your progress.