Why AI runs on Python

What Python is, why machine learning and agent frameworks settled on it, and how to read an eleven-line program one line at a time.

7 min Free

Python is a programming language that Guido van Rossum started in 1989 and first shared publicly in 1991. It is interpreted: you write a plain text file, and a program called the interpreter reads it from the top and runs each line. There is no separate compile step. The official FAQ describes Python as combining “remarkable power with very clear syntax”, and the clear syntax is the part you feel first: a Python program often reads like a description of what it does.

Almost every modern AI tool is written for Python. NumPy and pandas handle numbers and tables, PyTorch and TensorFlow train models, and the Agent Development Kit (ADK) builds agents. Three reasons keep pulling the field here. The language is readable, so researchers can share code and others can follow it. The ecosystem is huge, so whatever you need usually exists as a package you can install. And Python is a good glue language: the heavy maths runs in fast C and C++ code underneath, while your Python script just directs it.

You do not need to become a software engineer for this track. You need to read agent code, write small tool functions, and handle data such as lists and JSON. Every lesson in this track runs a short program one line at a time so you can see exactly what Python does.

Press Run to execute first.py, a batting summary. Watch the Variables panel fill up as names are created, and the Output panel as print() writes to the console.

Your first programReady
# first.py: your first Python program, a batting summary.
team = "India"
scores = [45, 62, 38, 71, 71]
total = sum(scores)
average = total / len(scores)

print("Team:", team)
print("Total runs:", total)
print("Average:", average)
if average > 50:
    print("Good batting day")

Press Play to run the program line by line, or step with ← →.

00/09

Variables

Nothing defined yet.

Output

Nothing printed yet.

What to notice

  1. Indentation is part of the language. The line under if average > 50: is indented, and that is what makes it belong to the if. Other languages use braces for this; Python uses the layout you would use anyway.
  2. You name values; you do not declare types. team = "India" attaches a name to a value. Python works out the type from the value. The next lesson, Variables, numbers and types, goes deeper.
  3. Built-in functions do the routine work. sum(), len() and print() come with the language. Most of the time you call something that exists rather than write it yourself.
  4. Read top to bottom, and the right side of = first. average = total / len(scores) computes the division, then stores the result under the name average.
  5. The file is the program. Save the text as first.py and run python3 first.py in a terminal. The next lesson shows how to set that up.

Why this matters for AI work

An ADK agent is a Python file. A tool is a Python function. An evaluation result is a list of dictionaries. When you can read eleven lines like these comfortably, you can open an agent’s source code, find the instruction, see which tools it has and spot what a tool returns. That is the real skill this track builds.

Check your understanding

1. What does the indented print() under if average > 50: do?
2. Why did machine learning and agent frameworks settle on Python?
3. In total = sum(scores), what is sum?