Chapter Topics

Chapter Topics#

The chapters progress from Python fundamentals, control flow, functions, and testing to core data structures and text processing, then to program design with objects, functional tools, iterators, and APIs, and finally to abstract data structures and algorithms. Preview, Lab, and Homework activities accompany each chapter.

Chapter

Topics

1. Introduction

Natural and formal languages; levels of abstraction; interpreted and compiled languages; expressions and statements; number systems and character encoding; indentation and statement formatting; input, output, and f-strings; built-in functions, modules, and packages.

2. Syntax and Types

Variables and naming conventions; objects, types, identity, and mutability; aliasing; assignment, arithmetic, and comparison operators; truthiness, membership, and identity; logical and bitwise operators; type checking, conversion, and hinting; strings and collection types.

3. Control Flow

if, else, and elif statements; nested conditionals; conditional expressions; iterators and iterables; for loops with range and nested loops; counting, sentinel, and infinite while loops; break and continue.

4. Functions

Defining functions and encapsulation; parameters, default values, *args, and **kwargs; return values and type annotations; Boolean functions; local and global scope; composition, pure functions, and docstrings; lambda functions; recursion and memoization.

5. Exceptions & Testing

Types of errors and tracebacks; try, except, else, and finally; raising exceptions and custom exception classes; debugging with print statements, assertions, and bisection; logging; unit testing with pytest; unittest and doctests; mocking, parametrized tests, and coverage.

6. Sequences

Creating and accessing lists; list comprehensions and nested lists; list operators, functions, and methods; enumerate, zip, and unpacking; aliasing and list arguments; shallow and deep copies; tuples and immutability; tuples as return values and records.

7. Dictionaries and Mapping

Creating dictionaries; accessing, updating, and deleting items; membership testing; dictionary comprehensions; counting with Counter and defaultdict; inverting and sorting dictionaries; hashable keys; sets, set algebra, and frozensets.

8. Strings and Text

Escape sequences, indexing, and slicing; string methods for searching, cleaning, splitting, and formatting; comparing and sorting strings; regular expressions with the re module; quantifiers, anchors, character classes, and groups; cleaning text and substitution; word frequencies; Markov text generation.

9. Object-Oriented Programming

Classes and instances; methods, __init__, and properties; __str__ and __repr__; encapsulation and polymorphism; inheritance and method overriding; abstract base classes; comparison methods and operator overloading; dataclasses, class methods, and static methods.

10. Functional Programming

Pure functions and immutability; functions as values; higher-order functions; decorators; comprehensions and choosing a style; recursion versus iteration; context managers; reduce, partial, and lru_cache from functools.

11. Iterators & Generators

The iterator protocol; built-in lazy iterators; custom iterator classes; generator functions; generator expressions; infinite sequences and yield from; itertools; async iteration.

12. APIs

Reading an API contract; GET requests with requests; query parameters; error handling and safe JSON fetching; POST requests; headers and API keys; nested JSON parsing and pagination; retries with exponential backoff and response validation.

13. Abstract Data Structures

Abstract types and implementations; operation tradeoffs; stacks; queues; trees; graphs and graph traversal.

14. Algorithms

Properties of algorithms; the design process; complexity and Big O; benchmarking; linear and binary search; the bisect module and hash-based lookup; built-in sorting with key functions; insertion, bubble, merge, and quick sort.

Each part also has an overview page: Part I, Part II, Part III, and Part IV.

Set up your environment with Course Tooling and Jupyter Setup in the appendices before the first lab.