Chapter 1 · Getting Started
Why Python for AI?
- Page 1 of 23
- 3 min read
If you want to work in AI — calling models like ChatGPT or Claude, preparing data, training a model or building an AI feature into an app — you will almost certainly do it in Python. This tutorial takes you from your very first line of Python to calling a real AI model from your own program.
Why Python, and not another language?
- It reads almost like English. Python was designed to be readable. Beginners learn it faster, and experienced engineers make fewer mistakes in it.
- The AI ecosystem lives here. NumPy and pandas for data, scikit-learn for classic machine learning, PyTorch for deep learning, Hugging Face for open models, and official SDKs from OpenAI, Anthropic and Google — all are Python first.
- One language, the whole journey. The same Python you write to clean a spreadsheet is what you use to train a model and to serve it behind an API.
- A huge community. Almost every error message you will ever see has already been asked about and answered online.
Python is not the fastest language. It does not need to be: the heavy number-crunching in libraries like NumPy and PyTorch is written in fast C and C++ underneath, and Python is the friendly layer you control it with.
A first taste
Here is a complete Python program. Do not worry about every detail yet — just notice how readable it is:
# A taste of Python: count the words in a few customer reviews
reviews = [
"Great product, fast delivery",
"Bad packaging",
"Works exactly as described, very happy",
]
for review in reviews:
words = len(review.split())
print(f"{words} words: {review}")Output:
4 words: Great product, fast delivery
2 words: Bad packaging
6 words: Works exactly as described, very happyA list of text, a loop over it, splitting text into words and printing a formatted line — by the end of chapter 2 you will be able to write this yourself.
What you will learn
| Chapter | You will be able to… |
|---|---|
| 1. Getting started | Install Python, set up an editor and run your first program |
| 2. Python basics | Use numbers, text, lists and dictionaries; make decisions; repeat work with loops; write functions |
| 3. Writing real programs | Use libraries, read and write files, handle errors and model things with classes |
| 4. Python for data | Do fast maths with NumPy, analyse tables with pandas and draw charts with Matplotlib |
| 5. Python for AI work | Call web APIs, call an LLM from code safely, and build a small AI tool |
How to study this tutorial
- Type the code yourself. Copy-pasting teaches your eyes; typing teaches your hands. Small typos and the errors they cause are part of learning.
- Change things. After an example works, change a number or a word and predict what will happen before you run it.
- Take the quizzes. Each part ends with a quiz — Easy after the basics, Medium after the data chapter, and a Hard final exam.
You do not need any programming experience. You only need a computer (or even just a browser — see the next page) and about an hour a day.