Why Python?

XKCD comic about Python

Big numbers out of the box

Chessboard and grains illustrating the doubling pattern

Image: McGeddon, CC BY-SA 4.0

total = 0
for power in range(64):
    total += 2 ** power

print(total)

Big numbers out of the box

import math

print(math.factorial(1000))

Big numbers out of the box

t = 1_800_000_000

print(t)
print(t + 0.1)
print(t + 0.000000001)
from decimal import Decimal

t = Decimal(1_800_000_000)

print(t)
print(t + Decimal("0.1"))
print(t + Decimal("0.000000001"))

Simple things are done simply

Swapping two variables

a, b = 1, 2
a, b = b, a

Checking a substring

if "@" in email:
    send_email(email)

Reading a text file

text = Path("notes.txt").read_text()

Simple things are done simply

Chained comparison

Checking whether an email already exists

exists = any(user.email == email for user in users)

Comprehensions

total = 0
for power in range(64):
    total += 2 ** power

print(total)
print(sum(2 ** power for power in range(64)))

Comprehensions

users = [
    User(id=1, name="Andrey Gein"),
    User(id=2, name="Ada Lovelace"),
    User(id=3, name="Guido van Rossum"),
]

names_by_id = {user.id: user.name for user in users}

Comprehensions

scores = {
    "Alice": 82,
    "Bob": 47,
    "Charlie": 91,
    "Diana": 58,
}

passed = {
    name: score
    for name, score in scores.items()
    if score >= 80
}

print(passed)

f-strings

Introduced in Python 3.6, 25 years after Python first appeared

Heavily improved in Python 3.12, three years ago

completed = 73
total = 120

# Before Python 3.6
print("Completed: {} out of {}. Progress: {:.1%}".format(completed, total, completed / total))

# Since Python 3.6
print(f"Completed: {completed} out of {total}. Progress: {completed / total:.1%}")

for + else

It means the loop finished without a break

for meeting in meetings:
    if meeting.overlaps(new_meeting):
        print(f"Conflict with {meeting.title}")
        break
else:
    meetings.append(new_meeting)
    print("Meeting scheduled")

Iris

Three similar species of Iris are distinguished by the length and width of their sepals and petals. Ronald Fisher described them in his 1936 paper

Machine learning with irises

sklearn, also known as scikit-learn, is a Python library with machine learning algorithms

from sklearn import datasets, ensemble

X, y = datasets.load_iris(return_X_y=True)

model = ensemble.RandomForestClassifier()
model.fit(X, y)

print(model.predict([[5.1, 3.5, 1.4, 0.2]]))

Analyze data

import pandas as pd
import matplotlib.pyplot as plt

data = pd.read_csv("temperature.csv")

data.plot(x="date", y="temperature")
plt.show()
Line chart of temperatures in August 2026

Jupyter notebooks

Ways to run notebooks

Google Colab notebook interface

Python keeps evolving

Python 3.10 — match and case

match point:
    case (0, 0):
        print("Origin")
    case (0, y):
        print(f"On the Y axis: {y}")
    case (x, 0):
        print(f"On the X axis: {x}")
    case (x, y):
        print(f"Point: {x}, {y}")

Python keeps evolving

Python 3.11 — Precise tracebacks

return abs(point_1.x - point_2.x)
                       ^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'x'

Python 3.13 — Helpful hints

"Hello!".split(max_split=1)
               ^^^^^^^^^
TypeError: got an unexpected keyword argument 'max_split'
Did you mean: 'maxsplit'?

Python keeps evolving

Python 3.12 — itertools.batched

from itertools import batched

for email_batch in batched(subscribers, 100):
    newsletter.send(to=email_batch)

Python 3.13 & 3.14 — Free-threaded build

python3.13t

Python keeps evolving

Python 3.14 — t-strings

Like f-strings, but preserve static text and interpolated values

variety = "Stilton"
template = t"Try some {variety} cheese!"

print(template)
print(template.strings)
print(template.values)

PEPs — Python Enhancement Proposals

  • PEP 750 — Template String Literals
  • Every major Python feature is standardised and described in a PEP
  • They make great reading — feel free to read them!
  • A PEP is a process: Proposal → Draft → Python standard

PEP 8 — Style Guide for Python Code

  • It standardises the conventions that make Python code familiar and easy to read
  • Names: function_name, ClassName, CONSTANT_NAME
  • Indentation: four spaces per indentation level, not tabs
  • Whitespace: total = price * quantity, not total=price*quantity
  • Layout: imports at the top and blank lines between top-level definitions
  • … and much more, check it out

Cool Python implementations

  • CPython — standard Python implementation written in C
  • PyPy — Python implementation written in Python
  • IronPython and Jython — .NET and Java implementations
  • … and many more
NumPy pandas Django PyTorch FastAPI Flask requests pytest scikit-learn TensorFlow Matplotlib SQLAlchemy Pydantic Polars SciPy JupyterLab IPython aiohttp transformers OpenCV Jinja2 tqdm Uvicorn beautifulsoup4 Scrapy Playwright PyArrow openpyxl httpx Rich Click Typer Ruff Black mypy uv Pillow PyYAML cryptography boto3 lxml OpenAI