An Introduction to Programming and Computer Science with Python, second edition
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
- Introduction
- Programming and the Python shell
- Types and literals
- Variables, statements, and expressions
- Functions
- Style
- Console I/O
- Branching, comparisons, and conditions
- Structure, development, and testing
- Sequences
- Loops, iteration, and iterables
- Randomness, games, and simulations
- File I/O
- Data analysis and presentation
- Exception handling
- Dictionaries, sets, and structured data
- 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
andUnicodeDecodeError
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()
andmath
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.