Module 1 of 6 · 25 minutes

Getting started with Python

No installation, no jargon. By the end of this module you'll be writing and running Python in your browser.

Learning objectives

  • Explain why Python dominates AI work
  • Run code in a Google Colab notebook
  • Use variables of different types
  • Format text with f-strings and string methods
  • Read and fix simple errors

1.1 Why Python for AI?

Python is the most widely used language in AI and data science. The Stanford AI Index 2026 (using Lightcast data) reports Python as the most in-demand specialised skill in AI job postings. Reasons:

  • Readable — code looks close to plain English.
  • Libraries — pandas for data, scikit-learn for machine learning, PyTorch for deep learning, and official SDKs from Anthropic, OpenAI, Google and others.
  • Notebooks — run code a cell at a time and see results immediately.
  • Community — almost every AI tutorial and course uses it.

1.2 Set up in two minutes: Google Colab

You don't need to install anything. Google Colab is a free, browser-based notebook. Sign in with a Google account, click New notebook, type code in a cell and press Shift+Enter to run it. (Alternatives: Jupyter on your computer, or VS Code with the Python extension.)

1.3 Your first lines of code

Python · run each cellprint("Hello, AI!")

# A comment: Python ignores anything after #
2 + 3 * 4          # in a notebook, the last line's value is shown: 14

1.4 Variables and types

A variable is a name for a value. Python works out the type for you.

product = "Bamboo board"     # str  (text)
price = 24.99                # float (decimal number)
stock = 120                  # int   (whole number)
in_stock = stock > 0         # bool  (True / False)

print(type(price))           # <class 'float'>
print(price * 1.2)           # 29.988
namevaluetypeproductrefers to"Bamboo board"strpricerefers to24.99floatstockrefers to120intin_stockrefers toTruebool
A variable is a name pointing at a value. Python works out each value's type for you.

1.5 Strings and f-strings

name = "Rey"
course = "Python for AI"
message = f"Welcome, {name}! You're taking {course}."
print(message)

review = "  The board is GREAT but arrived late.  "
print(review.strip().lower())          # "the board is great but arrived late."
print("late" in review.lower())        # True
print(len(review.strip()))             # number of characters

f-strings (note the f before the quote) are how you'll build prompts for AI models later.

1.6 Reading error messages

Errors are normal. Read the last line first — it names the error type and the problem.

print(price + " pounds")
# TypeError: unsupported operand type(s) for +: 'float' and 'str'
print(f"{price} pounds")     # fix: convert inside an f-string
Use AI to learn — wisely

AI assistants are excellent at explaining error messages and code. Paste the error and ask "explain this like I'm new to Python". But type the fix yourself and make sure you understand it — and never paste API keys or private data.

Exercise: price calculator

Create variables for a product name, a price excluding VAT and a VAT rate of 0.2. Print a sentence like "Bamboo board costs £29.99 including VAT", rounded to 2 decimal places.

Show a solution
name = "Bamboo board"
price_ex_vat = 24.99
vat_rate = 0.2
price_inc = round(price_ex_vat * (1 + vat_rate), 2)
print(f"{name} costs £{price_inc:.2f} including VAT")

Key takeaways

  • Python is the leading language for AI and data.
  • Colab runs Python in your browser for free.
  • Variables hold strings, numbers and booleans.
  • f-strings insert values into text — you'll use them to build prompts.
  • Read the last line of an error first.