The University of Vermont, 2023. — 402 p.
To the student.
Programming and the Python Shell.
Why learn a programming language?
Compilation and interpretation.
The Python shell.
Hello, Python!
Syntax and semantics.
Introduction to binary numbers.
Exercises.
Types and literals.
What are types?
Dynamic typing.
Types and memory.
More on string literals.
Representation error of numeric types.
Exercises.
Variables, statements, and expressions.
Variables and assignment.
Expressions.
Augmented assignment operators.
Euclidean or ``floor'' division.
Modular arithmetic.
Exponentiation.
Exceptions.
Exercises.
Functions.
Introduction to functions.
A deeper dive into functions.
Passing arguments to a function.
Scope.
Pure and impure functions.
The math module.
Exceptions.
Exercises.
Style.
The importance of style.
PEP 8.
Whitespace.
Names (identifiers).
Line length.
Constants.
Code comments.
Exercises.
Console I/O.
Motivation.
Command line interface.
The input() function.
Converting strings to numeric types.
Some ways to format output.
Python f-strings and string interpolation.
Format specifiers.
Scientific notation.
Formatting tables.
Example: currency converter.
Format specifiers: a quick reference.
Exceptions.
Exercises.
Branching and Boolean expressions.
Boolean logic and Boolean expressions.
Comparison operators.
Branching.
if, elif, and else.
Truthy and falsey.
Input validation.
Some string methods.
Flow charts.
Decision trees.
Exercises.
Structure, development, and testing.
main the Python way.
Program structure.
Iterative and incremental development.
Testing your code.
The origin of the term ``bug''.
Using assertions to test your code.
Rubber ducking.
Exceptions.
Exercises.
Sequences.
Lists.
Tuples.
Mutability and immutability.
Subscripts are indices.
Concatenating lists and tuples.
Copying lists.
Finding an element within a sequence.
Sequence unpacking.
Strings are sequences.
Sequences: a quick reference guide.
Slicing.
Passing mutables to functions.
Exceptions.
Exercises.
Loops and iteration.
Loops: an introduction.
while loops.
Input validation with while loops.
An ancient algorithm with a while loop.
for loops.
Iterables.
Iterating over strings.
Calculating a sum in a loop.
Loops and summations.
Products.
enumerate().
Tracing a loop.
Nested loops.
Stacks and queues.
A deeper dive into iteration in Python.
Exercises.
Randomness, games, and simulations.
The random module.
Pseudo-randomness in more detail.
Using the seed.
Exercises.
File I/O.
Context managers.
Reading from a file.
Writing to a file.
Keyword arguments.
More on printing strings.
The CSV module.
Exceptions.
Exercises.
Data analysis and presentation.
Some elementary statistics.
Python's statistics module.
A brief introduction to plotting with Matplotlib.
The basics of Matplotlib.
Exceptions.
Exercises.
Exception handling.
Exceptions.
Handling exceptions.
Exceptions and flow of control.
Exercises.
Dictionaries.
Introduction to dictionaries.
Iterating over dictionaries.
Deleting dictionary keys.
Hashtables.
Counting letters in a string.
Exceptions.
Exercises.
Graphs.
Introduction to graphs.
Searching a graph: breadth-first search.
Exercises.
Mathematical notation.
pip and venv.
File systems.
Code for cover artwork.