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.
Prerequisites
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)
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
- Build an agent you can trust
- Build a memory system for an agent
- Systems knowledge for AI engineers
- Evals in practice
- Train an agent with reward
- Statistics for experiments
- Build a RAG system you can trust
- Data: collect, clean, document
- An AI service in operation
- Multimodal systems
- AI safety in practice
- Training neural networks for real
- Run models more cheaply: quantisation
- AI in production
- Image classification with convolutional networks
- Build a transformer from scratch
- Train your first neural network
- Classical machine learning in practice
- Classical ML for real
- Fine-tune and run your own models
- Understand how generative AI works
- Foundations of computer science
- Deep reinforcement learning
- Fine-tune a model with LoRA
- Frontier Lab — an independent research project
- Responsible AI in practice
- Build an NLP system end to end
- Generative models in depth
- Build an AI service that survives production
- Build a voice interface
- Reproduce a paper
- Interpreting a language model
- AI, ethics and society