Python for AI and ML Crash Course

For programmers who know another language

CS 212 AI Programming 1

Introduction

In this course we write all of our AI programs in Python. You don’t need to be a Python expert to get started. If you already know another programming language, such as JavaScript, C#, or Java, most of what you know carries over, and you mainly need to learn Python’s syntax and a few of its distinctive features.

The Python notes for this course are spread across several units. This page lists them all in one place, in the order we suggest reading them. Each note is short and focused, so you can read the whole set like a crash course, or come back to a single note when you need a refresher.

Python Notes and Guides

  1. Intro to Python How to install Python on Windows and macOS, run a “Hello World” program, and use VS Code and its debugger. It also covers what makes Python different from C-family languages (indentation instead of curly braces, dynamic typing, no semicolons), Python’s programming paradigms, an object-oriented example, and a “die battle” exercise to translate into Python.

  2. Python Coding Style Cheat-Sheet A one-page summary of the PEP 8 style guide: indentation and line length, naming conventions (snake_case, CapWords, ALL_CAPS), comments, whitespace, docstrings, imports, and blank lines. Use it to make your code look pythonic.

  3. Python Collection Types The four built-in collection types: lists, dictionaries, sets, and tuples. Each one has a table showing its syntax, ordering, mutability, and whether it allows duplicates, plus examples. It also explains how to use dict.get() to look up a key safely.

  4. Python Loops How to use for loops to go through a sequence (including range()), how to use while loops to repeat code while a condition is true, and how break, continue, and a loop’s else clause change the flow of a loop.

  5. Python Projects Why each project needs its own virtual environment, and how to manage environments and packages in two ways: with Python’s built-in venv and pip tools (including requirements.txt), and with uv, the project manager we use in this course. It also explains pyproject.toml, the uv.lock file, using environments in VS Code, and how to fix common problems.

  6. Set Up Python Packages for ML An introduction to the machine learning libraries we’ll use later in the course (NumPy, scikit-learn, TensorFlow with Keras, Pillow, and Matplotlib), with instructions for installing them in a virtual environment on Windows and macOS.

More Python Resources


Note: This page was drafted with assistance from Claude Opus 5.5 10/19/2026


Creative Commons License AI Programming Course Materials by Brian Bird, written in are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.