Why Python for AI, ML, and GenAI
Start here. See why Python is the default language for machine learning and generative AI, how this course is organised, and run your first program in the on-site compiler.
Why this matters in AI / ML / GenAI
Job descriptions for ML engineers, GenAI engineers, MLOps, and LLMOps almost always list Python first. PyTorch, Hugging Face, LangChain, FastAPI, pandas, and most RAG tooling are Python-native. You will write training scripts, data jobs, APIs, and agent glue in this language.
What you will learn in this course
This is a free, self-paced Python course written for people who want to become AI/ML engineers or GenAI engineers — including those starting from zero.
You will move through four modules:
- Foundations — how Python stores values, text, collections, and decisions.
- Core language — functions, files, errors, classes, and how to structure programs.
- Data and ML Python — type hints, NumPy, pandas, tests, and logging.
- GenAI and production — HTTP/JSON, tensor thinking, prompts, FastAPI-style services, RAG building blocks, and production habits.
Every lesson has a short explanation, copy-paste examples, and a live compiler so you can run code without installing anything. The compiler is real CPython running in your browser (WebAssembly). It is perfect for learning. Production libraries such as PyTorch and FastAPI are shown as copy-paste examples you run locally later.
Why teams standardised on Python
Python is not the fastest language. Teams use it because the ecosystem is unmatched for data and models:
- NumPy / pandas for arrays and tables
- PyTorch / scikit-learn for training
- Hugging Face for models and tokenizers
- FastAPI for model and agent APIs
- LangChain / LangGraph for LLM apps
Readability matters. An ML pipeline is mostly glue: load data, transform it, call a model, write metrics, expose an endpoint. Clear Python is easier to review, test, and hand to the next engineer.
Three places you will use Python on the job:
| Place | Typical file | What it does |
|---|---|---|
| Research | notebook or train.py | Experiment and fit a model |
| Service | app.py / FastAPI | Serve predictions or an LLM |
| Ops | jobs, CI, eval scripts | Data, monitoring, evaluation |
Your first program
Python runs top to bottom. print() writes text to the output. Lines starting with # are comments and are ignored.
Indentation is syntax, not style. Other languages use braces {}. Python uses spaces. We will use four spaces everywhere. Mixing tabs and spaces causes errors — a common beginner trap.
Names should describe the value: learning_rate not lr1. That habit pays off when you read training configs six months later.
Copy-paste examples
Copy into your own editor, or load one into the compiler below and press Run.
Hello, engineer
print() shows values. Comments start with #.
# Python runs line by line.
print("Hello, AI engineer")
print("Python is the language of ML, GenAI, and MLOps.")A tiny config you will see in every training script
You are just storing numbers and text in names. Next lesson covers types in detail.
model_name = "bert-base-uncased"
batch_size = 32
learning_rate = 0.00002
print("model:", model_name)
print("batch_size:", batch_size)
print("learning_rate:", learning_rate)Run your first program
Try it — in-browser Python
Change the role string and press Run. Use Ctrl+Enter as a shortcut.
Output
Python runs in your browser. First run downloads the runtime.
Press Run (or Ctrl+Enter) to execute.
CPython in WebAssembly. Stdlib works. NumPy and pandas load on demand. No input(), no GPU, no network installs.
Takeaways
- Python is the shared language of ML training, GenAI apps, and MLOps glue code.
- This site includes a real in-browser compiler — use it on every lesson.
- print() displays output; # starts a comment; indentation is required.