An Introduction to Programming and Computer Science with Python, second edition

Published

July 11, 2025

An Introduction to Programming and Computer Science with Python, second edition is a free, open source textbook available under a CC BY-NC-SA license. Originally developed for UVM’s CS 1210 Introduction to Programming, it covers the basics of programming using Python, and a number of other topics of use in courses beyond CS 1210.

It is available in print and as free PDF, and selected material is included here on this website. For UVM students, hard copy available in UVM Bookstore (price should be around $14.00).

If you are using or planning to use this textbook in your own teaching, I’d love to hear from you.

Hard copy can be ordered by contacting me via email. Textbooks can be shipped straight from the printer. 530 pp. with complete index, 6” ⨉ 9” (152 ⨉ 229 mm), perfect bound, 1.55 lb (703 g), greyscale interior on #50 white paper, color cover with gloss finish. Price will vary depending on units and shipping cost (for reference, ~100 units shipped to Vermont works out to under $11.00 per unit).

Cafiero, Clayton. 2023–2025. An Introduction to Programming and Computer Science with Python, second edition. ISBN: 979-8-9887092-1-3. Revision history (from first print edition forward)

Chapters

  1. Introduction
  2. Programming and the Python shell
  3. Types and literals
  4. Variables, statements, and expressions
  5. Functions
  6. Style
  7. Console I/O
  8. Branching, comparisons, and conditions
  9. Structure, development, and testing
  10. Sequences
  11. Loops, iteration, and iterables
  12. Randomness, games, and simulations
  13. File I/O
  14. Data analysis and presentation
  15. Exception handling
  16. Dictionaries, sets, and structured data
  17. Graphs

Appendices

A. Glossary
B. Mathematical notation
C. pip and venv
D. File systems
E. Flow charts
F. Code for cover artwork
G. Code smells for beginners
H. The call stack
I. The joy of Unicode
J. A brief introduction to databases with SQLite

Feedback, including reports of errata, criticisms, suggestions, and proposed revisions, is warmly encouraged.

Second edition

Second edition adds the following:

  • expanded treatment of functions and scope, with coverage of free variables and Python’s LEGB resolution strategy;
  • coverage of UnboundLocalError and UnicodeDecodeError exceptions;
  • coverage of Python’s built-in sorted()
  • coverage of string methods .replace(), .join(), and .split();
  • coverage of sequence method .count();
  • using the keyword is to test for identity;
  • coverage of list method .extend();
  • coverage of random module functions .gauss() and .sample() and math module functions .exp(), .log(), .log2(), .log10(), .floor(), .ceil(), .degrees() and .radians();
  • sets;
  • expanded treatment of structured data including named tuples and the json module;
  • use and abuse of the global keyword;
  • strategies for dealing with long lines and PEP 8;
  • new exercises and comprehension checks; and
  • new appendices: Code smells for beginners, The call stack, The joy of Unicode, and An introduction to databases with SQLite.