Python — the basics
Be able to write and run a short Python program with variables, if statements, a function and printing, and to read an error message and understand where the fault is.
Intuition
Python is the language almost all AI code is written in. It reads almost like pseudocode:
score = 12
if score > 10:
print("Pass")
else:
print("Try again")
Indentation (four spaces) is not ornament — it decides what belongs to the if.
Code
A function packages code so it can be reused:
def vat(price):
return price * 0.25
print(vat(200)) # 50.0
Error messages are read from the bottom up. NameError: name 'price' is not defined means
you have used a name that does not exist — often a typo, or the variable is created
later in the code. TypeError means you have mixed kinds, for instance text + number.
Formal
The types you need first: int (whole numbers), float (decimals), str (text), bool
(True/False). type(x) shows the type. int("12") turns text into a number; str(12) does the
opposite. input() always gives a str — do not forget to convert.
Mastery means
- Writes a function with a parameter and a return value
- Interprets a common error message (NameError, TypeError)
Prerequisites
Sign in to do the exercises and build your mastery up.
Sources
Leads to
Part of the goals (37)
- From blocks to Python
- The mathematics behind the models
- The developer's toolbox
- Language models in practice
- Statistics for experiments
- Train an agent with reward
- Data: collect, clean, document
- Build a memory system for an agent
- Build an agent you can trust
- Systems knowledge for AI engineers
- Image classification with convolutional networks
- Training neural networks for real
- Train your first neural network
- Run models more cheaply: quantisation
- Build a transformer from scratch
- Classical machine learning in practice
- Build a RAG pipeline with traceable sources
- AI safety in practice
- Multimodal systems
- An AI service in operation
- AI in production
- Classical ML for real
- Understand how generative AI works
- Fine-tune and run your own models
- Fine-tune a model with LoRA
- Deep reinforcement learning
- Foundations of computer science
- Evals in practice
- Frontier Lab — an independent research project
- Build a voice interface
- Reproduce a paper
- Responsible AI in practice
- Build an NLP system end to end
- Build an AI service that survives production
- Generative models in depth
- Interpreting a language model
- AI, ethics and society