This book is licensed for the personal use of the buyer. Please do not share or resell the file. Short quotations with attribution are welcome.
The information in this book is provided for education. It is not legal, financial or other professional advice. Product and company names are used only to describe them and belong to their owners.
This is a free sample: the introduction and first chapter.
IntroductionIntroduction
You do not need a computer-science degree to work with AI in code. You need a solid grasp of a small part of one programming language, the confidence to experiment, and good habits for checking your work. This book gives you all three, using Python, the most widely used language for data and AI.
We start from absolute zero: what a program is, how to run one, and how to store and change values. Step by step, you will learn lists, dictionaries, decisions, loops and functions; then files, tables of data and charts; then how to call web services and language models from code. Three small projects bring everything together: a document summariser, a spreadsheet cleaner and a feedback classifier.
Every concept comes with a short example you can type and run. Type the examples yourself rather than copying them: your fingers learn as much as your eyes. Exercises appear at the end of many chapters, with solutions in the appendix.
How the book is organised
Chapters 1 to 12 cover the core language: running programs, values, text, numbers, lists, dictionaries, decisions, loops, functions, errors and modules.
Chapters 13 to 19 cover data: files, CSV and JSON, tables with pandas, cleaning, summarising and charts.
Chapters 20 to 22 connect to the outside world: web APIs, keeping secrets safe and calling a language model.
Chapters 23 to 25 are projects.
Chapters 26 to 29 add dates and times, text patterns, robust API calls and a document question-answering project.
Chapters 30 to 32 cover coding with an AI assistant, good habits and where to go next.
Chapter 1Why Python, and How to Start
Python is popular for AI because it is readable, has a huge ecosystem of libraries for data and machine learning, and is supported by almost every AI service. Code written in Python often reads almost like English.
Installing Python
You have two easy options:
Install Python from the official website, python.org, choosing a current version (3.10 or newer). On Windows, tick the option to add Python to your PATH during installation.
Use an online notebook environment, which runs Python in your browser with nothing to install. Many are free for learning.
To check an installation, open a terminal (Command Prompt or PowerShell on Windows, Terminal on Mac or Linux) and type:
python --version
On some systems the command is python3. You should see a version number such as Python 3.12.1.
An editor
You can write Python in any text editor, but a code editor helps with colours, indentation and error hints. Popular free editors work well. Notebooks are also excellent for learning, because you can run small pieces of code and see results immediately.
You have reached the end of the free sample. The full book continues with 31 more chapters, plus the appendices.