100% found this document useful (1 vote)
54 views

Instant download An Introduction to Programming and Computer Science with Python First Edition Clayton Cafiero pdf all chapter

Programming

Uploaded by

danocaltop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
54 views

Instant download An Introduction to Programming and Computer Science with Python First Edition Clayton Cafiero pdf all chapter

Programming

Uploaded by

danocaltop
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Download Full Version ebook - Visit ebookmeta.

com

An Introduction to Programming and Computer


Science with Python First Edition Clayton Cafiero

https://ebookmeta.com/product/an-introduction-to-
programming-and-computer-science-with-python-first-edition-
clayton-cafiero/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmeta.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

Data Structures and Algorithms with Python: With an


Introduction to Multiprocessing (Undergraduate Topics in
Computer Science) Lee
https://ebookmeta.com/product/data-structures-and-algorithms-with-
python-with-an-introduction-to-multiprocessing-undergraduate-topics-
in-computer-science-lee/
ebookmeta.com

Python An Introduction to Programming 2nd Edition Jim R.


Parker

https://ebookmeta.com/product/python-an-introduction-to-
programming-2nd-edition-jim-r-parker/

ebookmeta.com

An Introduction to Python Programming for Scientists and


Engineers Johnny Wei-Bing Lin

https://ebookmeta.com/product/an-introduction-to-python-programming-
for-scientists-and-engineers-johnny-wei-bing-lin/

ebookmeta.com

The New Real: Media and Mimesis in Japan from Stereographs


to Emoji Jonathan E. Abel

https://ebookmeta.com/product/the-new-real-media-and-mimesis-in-japan-
from-stereographs-to-emoji-jonathan-e-abel/

ebookmeta.com
AD Stufish : Entertainment Architecture 1st Edition Ray
Winkler

https://ebookmeta.com/product/ad-stufish-entertainment-
architecture-1st-edition-ray-winkler/

ebookmeta.com

Perfect Fit Flirty Fitness 1st Edition M.K. Moore & Flirt
Club

https://ebookmeta.com/product/perfect-fit-flirty-fitness-1st-edition-
m-k-moore-flirt-club/

ebookmeta.com

Studies on Plotinus and al Kindi Variorum Collected


Studies 1st Edition Peter Adamson

https://ebookmeta.com/product/studies-on-plotinus-and-al-kindi-
variorum-collected-studies-1st-edition-peter-adamson/

ebookmeta.com

Complete Chemistry for Cambridge Secondary 1 Student Book


For Cambridge Checkpoint and beyond CIE Checkpoint Gardom
Hulme
https://ebookmeta.com/product/complete-chemistry-for-cambridge-
secondary-1-student-book-for-cambridge-checkpoint-and-beyond-cie-
checkpoint-gardom-hulme/
ebookmeta.com

The American Construction Industry Its Historical


Evolution and Potential Future 1st Edition Brian Bowen

https://ebookmeta.com/product/the-american-construction-industry-its-
historical-evolution-and-potential-future-1st-edition-brian-bowen/

ebookmeta.com
Terrorism Criminal Law and Politics The Decline of the
Political Offence Exception to Extradition Transnational
Criminal Justice 1st Edition Julia Jansson
https://ebookmeta.com/product/terrorism-criminal-law-and-politics-the-
decline-of-the-political-offence-exception-to-extradition-
transnational-criminal-justice-1st-edition-julia-jansson/
ebookmeta.com
AN INTRODUCTION TO
PROGRAMMING AND COMPUTER SCIENCE
WITH PYTHON

CLAYTON CAFIERO
An Introduction to
Programming and Computer Science
with Python

Clayton Cafiero
The University of Vermont
This book is for free use under either the GNU Free Documentation License or
the Creative Commons Attribution-ShareAlike 3.0 United States License. Take
your pick.
• http://www.gnu.org/copyleft/fdl.html
• http://creativecommons.org/licenses/by-sa/3.0/us/

Book style has been adapted from the Memoir class for TEX, copyright © 2001–
2011 Peter R. Wilson, 2011–2022 Lars Madsen, and is thus excluded from the
above licence.
Images from Matplotlib.org in Chapter 15 are excluded from the license for
this material. They are subject to Matplotlib’s license at https://matplotlib.o
rg/stable/users/project/license.html. Photo of Edsger Dijkstra by Hamilton
Richards, University Texas at Austin, available under a Creative Commons CC
BY-SA 3.0 license: https://creativecommons.org/licenses/by-sa/3.0/.
No generative AI was used in writing this book.
Manuscript prepared by the author with Quarto, Pandoc, and XƎLATEX.
Illustrations, diagrams, and cover artwork by the author, except for the graph
in Chapter 17, Exercise 2, which is by Harry Sharman.
Version: 0.1.8b (beta)
ISBN: 979-8-9887092-0-6
Library of Congress Control Number: 2023912320
First edition
10 9 8 7 6 5 4 3 2
Printed in the United States of America
For the Bug and the Bull
Table of contents

Table of contents i

Preface v

To the student vii

Acknowledgements ix

1 Introduction 1

2 Programming and the Python Shell 11


2.1 Why learn a programming language? . . . . . . . . . . . . 12
2.2 Compilation and interpretation . . . . . . . . . . . . . . . 14
2.3 The Python shell . . . . . . . . . . . . . . . . . . . . . . . 16
2.4 Hello, Python! . . . . . . . . . . . . . . . . . . . . . . . . 18
2.5 Syntax and semantics . . . . . . . . . . . . . . . . . . . . 19
2.6 Introduction to binary numbers . . . . . . . . . . . . . . . 21
2.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

3 Types and literals 27


3.1 What are types? . . . . . . . . . . . . . . . . . . . . . . . . 28
3.2 Dynamic typing . . . . . . . . . . . . . . . . . . . . . . . . 31
3.3 Types and memory . . . . . . . . . . . . . . . . . . . . . . 33
3.4 More on string literals . . . . . . . . . . . . . . . . . . . . 35
3.5 Representation error of numeric types . . . . . . . . . . . 37
3.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4 Variables, statements, and expressions 43


4.1 Variables and assignment . . . . . . . . . . . . . . . . . . 44
4.2 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.3 Augmented assignment operators . . . . . . . . . . . . . . 54
4.4 Euclidean or “floor” division . . . . . . . . . . . . . . . . 54
4.5 Modular arithmetic . . . . . . . . . . . . . . . . . . . . . . 59
4.6 Exponentiation . . . . . . . . . . . . . . . . . . . . . . . . 66
4.7 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

5 Functions 75
5.1 Introduction to functions . . . . . . . . . . . . . . . . . . 76

i
ii Table of contents

5.2 A deeper dive into functions . . . . . . . . . . . . . . . . . 81


5.3 Passing arguments to a function . . . . . . . . . . . . . . 87
5.4 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
5.5 Pure and impure functions . . . . . . . . . . . . . . . . . 90
5.6 The math module . . . . . . . . . . . . . . . . . . . . . . . 91
5.7 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
5.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

6 Style 97
6.1 The importance of style . . . . . . . . . . . . . . . . . . . 97
6.2 PEP 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
6.3 Whitespace . . . . . . . . . . . . . . . . . . . . . . . . . . 98
6.4 Names (identifiers) . . . . . . . . . . . . . . . . . . . . . . 100
6.5 Line length . . . . . . . . . . . . . . . . . . . . . . . . . . 101
6.6 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
6.7 Comments in code . . . . . . . . . . . . . . . . . . . . . . 102
6.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

7 Console I/O 107


7.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
7.2 Command line interface . . . . . . . . . . . . . . . . . . . 108
7.3 The input() function . . . . . . . . . . . . . . . . . . . . . 108
7.4 Converting strings to numeric types . . . . . . . . . . . . 110
7.5 Some ways to format output . . . . . . . . . . . . . . . . 115
7.6 Python f-strings and string interpolation . . . . . . . . . 116
7.7 Format specifiers . . . . . . . . . . . . . . . . . . . . . . . 117
7.8 Scientific notation . . . . . . . . . . . . . . . . . . . . . . 118
7.9 Formatting tables . . . . . . . . . . . . . . . . . . . . . . . 118
7.10 Example: currency converter . . . . . . . . . . . . . . . . 121
7.11 Format specifiers: a quick reference . . . . . . . . . . . . . 124
7.12 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
7.13 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

8 Branching and Boolean expressions 129


8.1 Boolean logic and Boolean expressions . . . . . . . . . . . 130
8.2 Comparison operators . . . . . . . . . . . . . . . . . . . . 133
8.3 Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
8.4 if, elif, and else . . . . . . . . . . . . . . . . . . . . . . . 136
8.5 Truthy and falsey . . . . . . . . . . . . . . . . . . . . . . . 138
8.6 Input validation . . . . . . . . . . . . . . . . . . . . . . . . 139
8.7 Some string methods . . . . . . . . . . . . . . . . . . . . . 141
8.8 Flow charts . . . . . . . . . . . . . . . . . . . . . . . . . . 144
8.9 Decision trees . . . . . . . . . . . . . . . . . . . . . . . . . 149
8.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

9 Structure, development, and testing 155


9.1 main the Python way . . . . . . . . . . . . . . . . . . . . . 156
9.2 Program structure . . . . . . . . . . . . . . . . . . . . . . 161
9.3 Iterative and incremental development . . . . . . . . . . . 161
9.4 Testing your code . . . . . . . . . . . . . . . . . . . . . . . 167
9.5 The origin of the term “bug” . . . . . . . . . . . . . . . . 174
9.6 Using assertions to test your code . . . . . . . . . . . . . 176
Table of contents iii

9.7 Rubberducking . . . . . . . . . . . . . . . . . . . . . . . . 178


9.8 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
9.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

10 Sequences 183
10.1 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
10.2 Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
10.3 Mutability and immutability . . . . . . . . . . . . . . . . 194
10.4 Subscripts are indices . . . . . . . . . . . . . . . . . . . . 198
10.5 Concatenating lists and tuples . . . . . . . . . . . . . . . 199
10.6 Copying lists . . . . . . . . . . . . . . . . . . . . . . . . . 200
10.7 Finding an element within a sequence . . . . . . . . . . . 201
10.8 Sequence unpacking . . . . . . . . . . . . . . . . . . . . . 203
10.9 Strings are sequences . . . . . . . . . . . . . . . . . . . . . 205
10.10 Sequences: a quick reference guide . . . . . . . . . . . . . 206
10.11 Slicing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
10.12 Passing mutables to functions . . . . . . . . . . . . . . . . 210
10.13 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
10.14 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

11 Loops and iteration 217


11.1 Loops: an introduction . . . . . . . . . . . . . . . . . . . . 218
11.2 while loops . . . . . . . . . . . . . . . . . . . . . . . . . . 219
11.3 Input validation with while loops . . . . . . . . . . . . . . 224
11.4 An ancient algorithm with a while loop . . . . . . . . . . 227
11.5 for loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
11.6 Iterables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
11.7 Iterating over strings . . . . . . . . . . . . . . . . . . . . . 236
11.8 Calculating a sum in a loop . . . . . . . . . . . . . . . . . 236
11.9 Loops and summations . . . . . . . . . . . . . . . . . . . . 237
11.10 Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
11.11 enumerate() . . . . . . . . . . . . . . . . . . . . . . . . . . 238
11.12 Tracing a loop . . . . . . . . . . . . . . . . . . . . . . . . . 241
11.13 Nested loops . . . . . . . . . . . . . . . . . . . . . . . . . 245
11.14 Stacks and queues . . . . . . . . . . . . . . . . . . . . . . 247
11.15 A deeper dive into iteration in Python . . . . . . . . . . . 250
11.16 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252

12 Randomness, games, and simulations 257


12.1 The random module . . . . . . . . . . . . . . . . . . . . . . 258
12.2 Pseudo-randomness in more detail . . . . . . . . . . . . . 261
12.3 Using the seed . . . . . . . . . . . . . . . . . . . . . . . . 262
12.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264

13 File I/O 267


13.1 Context managers . . . . . . . . . . . . . . . . . . . . . . 268
13.2 Reading from a file . . . . . . . . . . . . . . . . . . . . . . 268
13.3 Writing to a file . . . . . . . . . . . . . . . . . . . . . . . . 269
13.4 Keyword arguments . . . . . . . . . . . . . . . . . . . . . 271
13.5 More on printing strings . . . . . . . . . . . . . . . . . . . 272
13.6 The csv module . . . . . . . . . . . . . . . . . . . . . . . . 273
13.7 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
iv Table of contents

13.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277

14 Data analysis and presentation 281


14.1 Some elementary statistics . . . . . . . . . . . . . . . . . . 281
14.2 Python’s statistics module . . . . . . . . . . . . . . . . . 287
14.3 A brief introduction to plotting with Matplotlib . . . . . 288
14.4 The basics of Matplotlib . . . . . . . . . . . . . . . . . . . 290
14.5 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
14.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295

15 Exception handling 299


15.1 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
15.2 Handling exceptions . . . . . . . . . . . . . . . . . . . . . 306
15.3 Exceptions and flow of control . . . . . . . . . . . . . . . 309
15.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

16 Dictionaries 311
16.1 Introduction to dictionaries . . . . . . . . . . . . . . . . . 311
16.2 Iterating over dictionaries . . . . . . . . . . . . . . . . . . 316
16.3 Deleting dictionary keys . . . . . . . . . . . . . . . . . . . 318
16.4 Hashables . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
16.5 Counting letters in a string . . . . . . . . . . . . . . . . . 321
16.6 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
16.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323

17 Graphs 325
17.1 Introduction to graphs . . . . . . . . . . . . . . . . . . . . 325
17.2 Searching a graph: breadth-first search . . . . . . . . . . . 327
17.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330

Appendices 333
A Glossary 333

B Mathematical notation 363

C pip and venv 365

D File systems 369

E Code for cover artwork 373


Preface

This book has been written for use in University of Vermont’s CS1210
Introduction to Programming (formerly CS021). This is a semester long
course which covers much of the basics of programming, and an intro-
duction to some fundamental concepts in computer science. Not being
happy with any of the available textbooks, I endeavored to write my own.
Drafting began in August 2022, essentially writing a chapter a week over
the course of the semester, delivered to students via UVM’s learning
management system. The text was revised, edited, and expanded in the
following semester.
UVM’s CS1210 carries “QR” (quantitative reasoning) and “QD”
(quantitative and data literacy) designations. Accordingly, there’s some
mathematics included:

• writing functions to perform calculations,


• writing programs to generate interesting integer sequences,
• demonstrating the connection between pure functions and mathe-
matical functions,
• demonstrating the connection between list indices and subscript
notation,
• demonstrating that summations are loops,

and so on, to address the QR requirement. To address the QD require-


ment, we include some simple plotting with Matplotlib. Other aspects
of these requirements are addressed in programming assignments, lab
exercises, and lecture.
Nevertheless, despite this book’s primary objective as instructional
material for a specific course at UVM, others may find this material
useful.

–CC, July 2023

v
vi Preface

Errata and suggestions


I’m fully aware that this text isn’t quite “ready for prime time,” but, as
it’s been said “time and tide wait for no one,” and a new semester ap-
proaches. So we push this unfinished work out of the nest, and hope for
the best. If you have errata (which I’m certain are abundant) or sugges-
tions, I’m all ears and I welcome your feedback—bouquets or brickbats
or anything in between.

Contact
Clayton Cafiero
The University of Vermont
College of Engineering and Mathematical Sciences
Department of Computer Science
Innovation E309
82 University Place
Burlington, VT 05405-0125 (USA)

[email protected]
https://www.uvm.edu/~cbcafier
To the student

Learning how to program is fun and rewarding, but it demands a rather


different, structured approach to problem solving. This comes with time
and practice. While I hope this book will help you learn how to solve
problems with code, the only way to learn programming is by doing it.
There’s more than a little trial and error involved. If you find yourself
struggling, don’t despair—it just takes time and practice.
You will make mistakes—that’s part of the process. As John Dewey
once said “Failure is instructive. The person who really thinks learns
quite as much from their failures as from their successes.”
You’ll notice in this book that there are abundant examples given
using the Python shell. The Python shell is a great way to experiment
and deepen your understanding. I encourage you to follow along with
the examples in the book, and enter them into the shell yourself. Unlike
writing programs and then running them, interacting with the Python
shell gives you immediate feedback. If you don’t understand something
as well as you’d like, turn to the shell. Experiment there, and then go
back to writing your program.
If you take away only one thing from a first course in programming, it
should not be the details of the syntax of the language. Rather, it should
be an ability to decompose a problem into smaller units, to solve the
smaller problems in code, and then to build up a complete solution from
smaller subproblems. The primary vehicle for this approach is functions.
So make sure you gain a firm grasp of functions (see in particular Chapter
5).
Good luck and happy coding!

vii
Acknowledgements

Thanks to my colleagues, students, and teaching assistants in the Depart-


ment of Computer Science at the University of Vermont for motivation,
encouragement, suggestions, feedback, and corrections. Without you, this
book would not exist. Thanks to Chris Skalka for support and encour-
agement, for the opportunity to teach, and for luring me back to UVM.
Thanks to Isaac Levy for stimulating conversations on Python, and for
feedback on early drafts that he used in his own teaching. Thanks to
Jackie Horton, particularly for helpful comments on Chapter 3. Thanks
to Jim Eddy for helping me through my first semester of teaching CS1210
(back when it was CS021). Thanks to Sami Connolly for using a prelim-
inary draft in her own teaching and providing feedback. Thanks to Lisa
Dion for morning check-ins and Joan “Rosi” Rosebush for regular choco-
late deliveries. Thanks to Harry Sharman for helping with much of the
painstaking work of turning words into a book, and for contributing a
few of the exercises and Appendix D. Thanks to Deborah Cafiero for
proofreading and patience. Thanks to Jim Hefferon who has served as a
role model without knowing it.
Since the release of the first print edition, the following people have re-
ported defects and provided corrections: Murat Güngör, Daniel Triplett,
AG, Nina Holm, Colin Menuchi, Shiloh Chiu, Ted Pittman, Milan Chirag
Shah, Andrew Slowman, JD. Thank you all.

ix
Chapter 1

Introduction
Computer science is a science of abstraction—creating
the right model for a problem and devising the appro-
priate mechanizable techniques to solve it.
–Alfred V. Aho

The goal of this book is to provide an introduction to computer pro-


gramming with Python. This includes

• functional decomposition and a structured approach to program-


ming,
• writing idiomatic Python,
• understanding the importance of abstraction,
• practical problem-solving exercises, and
• a brief introduction to plotting with Matplotlib.

When you get to know it, Python is a peculiar programming lan-


guage.1 Much of what’s peculiar about Python is concealed by its seem-
ingly simple syntax. This is part of what makes Python a great first
language—and it’s fun!

Organization of this book


The book is organized into chapters which roughly correspond to a week’s
worth of material (with some deviations). Some chapters, particularly
the first few, should be consumed at a rate of two a week. We present
below a brief description of each chapter, followed by mention of some
conventions used in the book.

Programming and the Python shell


This chapter provides some motivation for why programming languages
are useful, and gives a general outline of how a program is executed by the
1
It’s not quite sui generis—Python is firmly rooted in the tradition of ALGOL-
influenced programming languages.

1
2 Introduction

Python interpreter. This chapter also introduces the two modes of using
Python. The interactive mode allows the user to interact with the Python
interpreter using the Python shell. Python statements and expressions
are entered one at a time, and the interpreter evaluates or executes the
code entered by the user. This is an essential tool for experimentation
and learning the details of various language features. Script mode allows
the user to write, save, and execute Python programs. This is convenient
since in this mode we can save our work, and run it multiple times
without having to type it again and again at the Python shell.
This chapter also includes a brief introduction to binary numbers and
binary arithmetic.

Types and literals


The concept of type is one of the most important in all computer science
(indeed there’s an entire field called “type theory”).
This chapter introduces the most commonly used Python types,
though in some cases, complete presentation of a given type will come
later in the text—lists and dictionaries, for example. Other types are
introduced later in the text (e.g., function, range, enumerate, etc.). As
types are introduced, examples of literals of each type are given.
Since representation error is a common cause of bewilderment among
beginners, there is some discussion of why this occurs with float objects.

Variables, statements, and expressions


This chapter introduces much of the machinery that will be used through-
out the remainder of the text: variables, assignment, expressions, opera-
tors, and evaluation of expressions.
On account of its broad applicability, a substantial account of modular
arithmetic is presented as well.

Functions
Functions are the single most important concept a beginning programmer
can acquire. Functional decomposition is a crucial requirement of writing
reliable, robust, correct code.
This chapter explains why we use functions, how functions are defined,
how functions are called, and how values are returned. We’ve tried to
keep this “non-technical” and so there’s no discussion of a call stack,
though there is discussion of scope.
Because beginning programmers often introduce side effects into func-
tions where they are undesirable or unnecessary, this chapter makes clear
the distinction between pure functions (those without side effects) and
impure functions (those with side effects, including mutating mutable
objects).
Because the math module is so widely used and includes many useful
functions, we introduce the math module in this chapter. In this way, we
also reinforce the idea of information hiding and good functional design.
Do we need to know how the math module implements its sqrt() function?
Of course not. Should we have to know how a function is implemented
3

in order to use it? Apart from knowing what constitutes a valid input
and what it returns as an output, no, we do not!

Style
Our goal here is to encourage the writing of idiomatic Python. Accord-
ingly, we address the high points of PEP 8—the de facto style guide for
Python—and provide examples of good and bad style.
Students don’t always understand how important style is for the read-
ability of one’s code. By following style guidelines we can reduce the
cognitive load that’s required to read code, thereby making it easier to
reason about and understand our code.

Console I/O (input/output)


This chapter demonstrates how to get input from the user (in command
line programs) and how to format output using f-strings. Because f-
strings have been around so long now, and because they allow for more
readable code, we’ve avoided presentation of older, and now seldom used,
C-style string formatting.

Branching
Branching is a programming language’s way of handling conditional ex-
ecution of code. In this chapter, we cover conditions (Boolean expres-
sions) which evaluate to a true or false (or a value which is “truthy”
or “falsey”—like true or like false). Python uses these conditions to de-
termine whether a block of code should be executed. In many cases we
have multiple branches—multiple paths of execution that might be taken.
These are implemented with if, elif (a portmanteau of “else if”), and
often else.
One common confusion that beginners face is understanding which
branch is executed in an if/elif/else structure, and hopefully the chapter
makes this clear.
Also covered are nested if statements, and two ways of visually rep-
resenting branching (each appropriate to different use cases)—decision
trees and flow charts.

Structure, development, and testing


Beginners often struggle with how to structure their code—both for
proper flow of execution and for readability. This chapter gives clear
guidelines for structuring code based on common idioms in Python. It
also addresses how we can incrementally build and test our code.
Unlike many introductory texts, we present assertions in this chapter.
Assertions are easy to understand and their use has great pedagogical
value. In order to write an assertion, a programmer must understand
clearly what behavior or output is expected for a given input. Using
assertions helps you reason about what should be happening when your
code is executed.
4 Introduction

Sequences
Sequences—lists, tuples, and strings—are presented in this chapter. It
makes sense to present these before presenting loops for two reasons.
First, sequences are iterable, and as such are used in for loops, and with-
out a clear understanding of what constitutes an iterable, understanding
such loops may present challenges. Second, we often do work within a
loop which might involve constructing or filtering a list of objects.
Common features of sequences—for example, they are all indexed,
support indexed reads, and are iterable—are highlighted throughout the
chapter.
As this chapter introduces our first mutable type, the Python list, we
present the concepts of mutability and immutability in this chapter.

Loops
Loops allow for repetitive work or calculation. In this chapter we present
the two kinds of loop supported by Python—while loops and for loops.
At this point, students have seen iterables (in the form of sequences)
and Boolean expressions, which are a necessary foundation for a proper
presentation of loops.
Also, this chapter introduces two new types—range and enumerate—
and their corresponding constructors. Presentation of range entails dis-
cussion of arithmetic sequences, and presentation of enumerate works
nicely with tuple unpacking (or more generally, sequence unpacking),
and so these are presented first in this chapter.
This chapter also provides a brief introduction to stacks and queues,
which are trivially implemented in Python using list as an underlying
data structure.
I’ve intentionally excluded treatment of comprehensions since begin-
ners have difficulty reading and writing comprehensions without a prior,
solid foundation in for loops.

Randomness, games, and simulations


There are many uses for randomness. Students love to write programs
which implement games, and many games involve some chance element or
elements—rolling dice, spinning a wheel, tossing a coin, shuffling a deck,
and so on. Another application is in simulations, which may also include
some chance elements. All manner of physical and other phenomena can
be simulated with some randomness built in.
This chapter presents Python’s random module, and some of the more
commonly used methods within this module—random.random(), ran-
dom.randint(), random.choice(), and random.shuffle(). Much of this is
done within the context of games of chance, but we also include some
simulations (e.g., random walk and Gambler’s Ruin). There is also some
discussion of pseudo-random numbers and how Python’s pseudo-random
number generator is seeded.

File I/O (input/output)


This chapter shows you how to read data from and write data to a file.
File I/O is best accomplished using a context manager. Context man-
5

agers were introduced with Python 2.5 in 2006, and are a much preferred
idiom (as compared to using try/finally). Accordingly, all file I/O demon-
strations make use of context managers created with the Python keyword
with.
Because so much data is in CSV format (or can be exported to this
format easily), we introduce the csv module in this chapter. Using the
csv module reduces some of the complexity we face when reading data
from a file, since we don’t have to parse it ourselves.

Exception handling
In this chapter, we present simple exception handling (using try/except,
but not finally), and explain that some exceptions should not be han-
dled since in doing so, we can hide programming defects which should
be corrected. We also demonstrate the use of exception handling in in-
put validation. When you reach this chapter, you’ll already have seen
while loops for input validation, so the addition of exception handling
represents only an incremental increase in complexity in this context.

Data analysis and presentation


This chapter is motivated in large part by the University of Vermont’s
QD (quantitative and data literacy) designation for the course for which
this textbook was written. Accordingly, we present some very basic de-
scriptive statistics and introduce Python’s statistics module including
statistics.mean(), statistics.pstdev(), and statistics.quantiles().
The presentation component of this chapter is done using Matplotlib,
which is the de facto standard for plotting and visualization with Python.
This covers only the rudiments of Matplotlib’s Pyplot interface (line plot,
bar plot, etc.), and is not intended as a complete introduction.

Dictionaries
Dictionaries are the last new type we present in the text. Dictionaries
store information using a key/value model—we look up values in a dic-
tionary by their keys. Like sequences, dictionaries are iterable, but since
they have keys rather than indices, this works a little differently. We’ll
see three different ways to iterate over a dictionary.
We’ll also learn about hashability in the context of dictionary keys.

Graphs
Since graphs are so commonplace in computer science, it seems appro-
priate to include a basic introduction to graphs in this text. Plus, graphs
are really fun!
A graph is a collection of vertices (also called nodes) and edges, which
connect the vertices of the graph. The concrete example of a highway map
is used, and an algorithm for breadth-first search (BFS) is demonstrated.
Since queues were introduced in chapter 11, the conceptual leap here—
using a queue in the BFS algorithm—shouldn’t be too great.
6 Introduction

Assumptions regarding prior knowledge of mathematics


This text assumes a reasonable background in high-school algebra and a
little geometry (for example, the Pythagorean theorem and right trian-
gles). Prior exposure to summations and subscripts would help the reader
but is not essential, as these are introduced in the text. The same goes
for mean, standard deviation, and quantiles. You might find it helpful if
you’ve seen these before, but these, too, are introduced in the text.
The minimum expectation is that you can add, subtract, multiply
and divide; that you understand exponents and square roots; and that
you understand the precedence of operations, grouping of expressions
with parentheses, and evaluating expressions with multiple terms and
operations.

Assumptions regarding prior knowledge of computer use


While this book assumes no prior knowledge whatsoever when it comes
to programming, it does assume that you have some familiarity with
using a computer and have a basic understanding of your computer’s file
system (a hierarchical system consisting of files and directories). If you
don’t know what a file is, or what a directory is, see Appendix D, or
consult documentation for your operating system. Writing and running
programs requires that you understand the basics of a computer file
system.

Typographic conventions used in this book


Names of functions, variables, and modules are rendered in fixed-pitch
typeface, as are Python keywords, code snippets, and sample output.

print("Hello, World!")

When referring to structures which make use of multiple keywords we


render these keywords separated by slashes but do not use fixed-pitch
typeface. Examples: if/else, if/elif, if/elif/else, try/except, try/finally,
etc.
File names, e.g., hello_world.py, and module names, e.g., math, are
also rendered in fixed-pitch typeface.
Where it is understood that code is entered into the Python shell,
the interactive Python prompt >>> is shown. Wherever you see this, you
should understand we’re working in Python shell. >>> should never ap-
pear in your code.2 Return values and evaluation of expressions are in-
dicated just as they are in the Python shell, without the leading >>>.

>>> 1 + 2
3
>>> import math
>>> math.sqrt(36)
6

2
Except in the case of doctests, which are not presented in this text.
7

In a few places, items which are placeholders for actual values or


variable names are given in angle brackets, thus <foo>. For example, when
describing the three-argument syntax for the range() function, we might
write range(<start>, <stop>, <stride>) to indicate that three arguments
must be supplied—the first for the start value, the second for the stop
value, and the last for the stride. It’s important to understand that the
angle brackets are not part of the syntax, but are merely a typographic
convention to indicate where an appropriate substitution must be made.
All of these conventions are in accord with the typographical conven-
tions used in the official Python documentation at python.org. Hopefully,
this will make it easier for students when they consult the official docu-
mentation.
Note that this use of angle brackets is a little different when it comes
to traceback messages printed when exceptions occur. There you may
see things like <stdin> and <module>, and in this context, they are not
placeholders requiring substitution by the user.

Other conventions
When referring to functions, whether built-in, from some imported mod-
ule, or otherwise, without any other context or specific problem instance,
we write function identifiers along with parentheses (as a visual indica-
tor that we’re speaking of a function) but without formal parameters.
Example: “The range() function accepts one, two, or three arguments.”
This should not be read as suggesting that range() takes no arguments.

Entry point / top-level code environment


As noted in the text, unlike many other languages such as C, C++,
Java, etc., a function named main() has no special meaning in Python
whatsoever. The correct way to specify the entry point of your code in
Python is with

if __name__ == '__main__':
# the rest of your code here

This is explained fully in Chapter 9.


In code samples in the book, we do, however, avoid using this if there
are no function definitions included in the code. We do this for space
and conciseness of the examples. The same could reasonably apply to
your code. In most cases, if there are no function definitions in your
module, there’s no need for this if statement (though it’s fine to include
it). However, if there are any function definitions in your module, then
if __name__ == '__main__': is the correct, Pythonic way to segregate
your driver code from your function definitions.

Origin of Python
Python has been around a long time, with the first release appearing
in 1991 (four years before Java). It was invented by Guido van Rossum,
who is now officially Python’s benevolent dictator for life (BDFL).
8 Introduction

Python gets its name from the British comedy troupe Monty Python’s
Flying Circus (Guido is a fan).
Nowadays, Python is one of the most widely used programming lan-
guages on the planet and is supported by an immense ecosystem and
thriving community. See: https://python.org/ for more.

Python version
As this book is written, the current version of Python is 3.11.4. However,
no new language features introduced since version 3.6 are presented in
this book (as most are not appropriate or even useful for beginners).
This book does cover f-strings, which were introduced in version 3.6.
Accordingly, if you have Python version 3.6–3.11, you should be able to
follow along with all code samples and exercises.

Using the Python documentation


For beginners and experts alike, a language’s documentation is an essen-
tial resource. Accordingly, it’s important that you know how to find and
consult Python’s online documentation.
There are many resources available on the internet and the quality
of these resources varies from truly awful to superb. The online Python
documentation falls toward the good end of that spectrum.

Pros
• Definitive and up-to-date
• Documentation for different versions clearly specified
• Thorough and accurate
• Includes references for all standard libraries
• Available in multiple languages
• Includes a comprehensive tutorial for Python beginners
• Coding examples (where given) conform to good Python style (PEP
8)

Cons
• Can be lengthy or technical—not always ideal for beginners
• Don’t always appear at top of search engine results.

python.org
Official Python documentation, tutorials, and other resources are hosted
at https://python.org.
9

• Documentation: https://docs.python.org/3/
• Tutorial: https://docs.python.org/3/tutorial/
• Beginner’s Guide: https://wiki.python.org/moin/BeginnersGuide

I recommend these as the first place to check for online resources.

Á Warning

There’s a lot of incorrect, dated, or otherwise questionable code on


the internet. Be careful when consulting sources other than official
documentation.
Chapter 2

Programming and the Python


Shell

Our objective for this chapter is to lay the foundations for the rest of
the course. If you’ve done any programming before, some of this may
seem familiar, but read carefully nonetheless. If you haven’t done any
programming before that’s OK.

Learning objectives
• You will learn how to interact with the Python interpreter using
the Python shell.
• You will learn the difference between interactive mode (in the shell)
and script mode (writing, saving, and running programs).
• You will learn a little about computers, how they are structured,
and that they use binary code.
• You will understand why we wish to write code in something other
than just zeros and ones, and you’ll learn a little about how Python
translates high-level code (written by you, the programmer) into
binary instructions that a computer can execute.
• You will write, save, and run your first Python program—an or-
dered collection of statements and expressions.

Terms introduced
• binary code
• bytecode
• compilation vs interpretation
• compiler
• console
• integrated development environment (IDE)
• interactive mode
• low-level vs high-level programming language
• Python interpreter / shell
• read-evaluate-print loop (REPL)
• semantics
• script mode
11
12 Programming and the Python Shell

• syntax
• terminal

2.1 Why learn a programming language?


Computers are powerful tools. Computers can perform all manner of
tasks: communication, computation, managing and manipulating data,
modeling natural phenomena, and creating images, videos, and music,
just to name a few. However, computers don’t read minds (yet), and
thus we have to provide instructions to computers so they can perform
these tasks.
Computers don’t speak natural languages (yet)—they only under-
stand binary code. Binary code is unreadable by humans.
For example, a portion of an executable program might look like this
(in binary):

0110101101101011 1100000000110101 1011110100100100


1010010100100100 0010100100010011 1110100100010101
1110100100010101 0001110110000000 1110000111100000
0000100000000001 0100101101110100 0000001000101011
0010100101110000 0101001001001001 1010100110101000

This is unintelligible. It’s bad enough to try to read it, and it would be
even worse if we had to write our computer programs in this fashion.
Computers don’t speak human language, and humans don’t speak
computer language. That’s a problem. The solution is programming lan-
guages.
Programming languages allow us, as humans, to write instructions
in a form we can understand and reason about, and then have these
instructions converted into a form that a computer can read and execute.
There is a tremendous variety of programming languages. Some lan-
guages are low-level, like assembly language, where there’s roughly a
one-to-one correspondence between machine instructions and assembly
language instructions. Here’s a “Hello World!” program in assembly lan-
guage (for ARM64 architecture):1

.equ STDOUT, 1
.equ SVC_WRITE, 64
.equ SVC_EXIT, 93

.text
.global _start

_start:
stp x29, x30, [sp, -16]!
mov x0, #STDOUT
ldr x1, =msg
mov x2, 13

1
Assembly language code sample from Rosetta Code: https://www.rosettacode.
org/wiki/Hello_world
Why learn a programming language? 13

mov x8, #SVC_WRITE


mov x29, sp
svc #0 // write(stdout, msg, 13);
ldp x29, x30, [sp], 16
mov x0, #0
mov x8, #SVC_EXIT
svc #0 // exit(0);

msg: .ascii "Hello World!\n"


.align 4

Now, while this is a lot better than a string of zeros and ones, it’s not
so easy to read, write, and reason about code in assembly language.
Fortunately, we have high-level languages. Here’s the same program
in C++:

#include <iostream>

int main () {
std::cout << "Hello World!" << std::endl;
}

Much better, right?


In Python, the same program is even more succinct:

print('Hello World!')

Notice that as we progress from machine code to Python, we’re in-


creasing abstraction. Machine code is the least abstract. These are the ac-
tual instructions executed on your computer. Assembly code uses human-
readable symbols, but still retains (for the most part) a one-to-one corre-
spondence between assembly instructions and machine instructions. In
the case of C++, we’re using a library iostream to provide us with an ab-
straction of an output stream, std::cout, and we’re just sending strings
to that stream. In the case of Python, we simply say “print this string”
(more or less). This is the most abstract of these examples—we needn’t
concern ourselves with low-level details.
14 Programming and the Python Shell

Figure 2.1: Increasing abstraction

Now, you may be wondering: How is it that we can write programs in


such languages when computers only understand zeros and ones? There
are programs which convert high-level code into machine code for ex-
ecution. There are two main approaches when dealing with high-level
languages, compilation and interpretation.

2.2 Compilation and interpretation


Generally speaking, compilation is a process whereby source code in some
programming language is converted into binary code for execution on a
particular architecture. The program which performs this conversion is
called a compiler. The compiler takes source code (in some programming
language) as an input, and yields binary machine code as an output.

Figure 2.2: Compilation (simplified)

Interpreted languages work a little differently. Python is an inter-


preted language. In the case of Python, intermediate code is generated,
and then this intermediate code is read and executed by another program.
The intermediate code is called bytecode.
Compilation and interpretation 15

While the difference between compilation and interpretation is not


quite as clear-cut as suggested here, these descriptions will serve for the
present purposes.

The Python interpreter


Python is an interpreted language with intermediate bytecode. While
you don’t need to understand all the details of this process, it’s helpful
to have a general idea of what’s going on.
Say you have written this program and saved it as hello_world.py.

print('Hello World!')

You may run this program from the terminal (command prompt), thus:

$ python hello_world.py

where $ indicates a command prompt (your prompt may vary). When


this runs, the following is printed to the console:

Hello World!

When we run this program, Python first reads the source code, then
produces the intermediate bytecode, then executes each instruction in
the bytecode.

Figure 2.3: Execution of a Python program


Exploring the Variety of Random
Documents with Different Content
simply grant to men the power which they may be pleased to
assume, it must be obvious to every one, what a door will be
opened for tyranny, which ought never to be seen in the Church of
Christ.
II. Here, therefore, it is necessary to remember, that whatever
authority and dignity is attributed by the Holy Spirit, in the Scripture,
either to the priests and prophets under the law, or to the apostles
and their successors, it is all given, not in a strict sense to the
persons themselves, but to the ministry over which they were
appointed, or, to speak more correctly, to the word, the ministration
of which was committed to them. For if we examine them all in
succession, we shall not find that they were invested with any
authority to teach or to answer inquiries, but in the name and word
of the Lord. For when they were called to their office, it was at the
same time enjoined that they should bring forward nothing of
themselves, but should speak from the mouth of the Lord. Nor did
he send them forth in public to address the people, before he had
instructed them what they should say, that they might speak nothing
beside his word. Moses himself, the prince of all the prophets, was
to be heard above all others; but he was first furnished with his
commission, that he might not be able to announce any thing except
from the Lord. Therefore the people, when they received his
doctrine, were said to “believe the Lord and his servant Moses.”[904]
The authority of the priests also, that it might not fall into contempt,
was confirmed by the severest punishments.[905] But, on the other
hand, the Lord shows on what condition they were to be heard,
when he says, “My covenant was with Levi. The law of truth was in
his mouth.” And just afterwards, “The priest’s lips should keep
knowledge, and they should seek the law at his mouth; for he is the
messenger of the Lord of hosts.”[906] Therefore, if a priest would be
heard, it was necessary for him to prove himself the messenger of
God, by faithfully communicating the commands which he had
received from his master; and where attention to the priests is
enjoined, it is expressly stated, that “they shall teach the sentence of
the law”[907] of God.
III. The power of the prophets is fully and beautifully described in
Ezekiel. “Son of man,” says the Lord, “I have made thee a watchman
unto the house of Israel; therefore hear the word at my mouth, and
give them warning from me.”[908] When he is commanded to hear
from the mouth of the Lord, is he not prohibited to invent any thing
of himself? And what is it to give warning from the Lord, but, to
speak in such a manner as to be able to declare with confidence that
the message he has brought is not his own, but the Lord’s? The Lord
expresses the same thing in other words in the prophecy of
Jeremiah: “The prophet that hath a dream, let him tell a dream; and
he that hath my word, let him speak my word faithfully.”[909] He
clearly delivers a law for them all; its import is, that he permits no
one to teach more than he has been commanded; and he afterwards
gives the appellation of “chaff” to every thing that has not
proceeded from himself alone. Not one of the prophets opened his
mouth, therefore, without having first received the words from the
Lord. Hence their frequent use of these expressions: “The word of
the Lord,” “The burden of the Lord,” “Thus saith the Lord,” “The
mouth of the Lord hath spoken;” and this was highly necessary; for
Isaiah exclaimed, “I am a man of unclean lips;”[910] and Jeremiah
said, “Behold, I cannot speak, for I am a child.”[911] What could
proceed from the pollution of the one, and the folly of the other, but
impure and foolish speeches, if they had spoken their own words?
But their lips were holy and pure, when they began to be the organs
of the Holy Spirit. While the prophets were bound by this law to
deliver nothing but what they had received, they were likewise
adorned with eminent power and splendid titles. For when the Lord
declares, “See, I have this day set thee over the nations, and over
the kingdoms, to root out, and to pull down, and to destroy, and to
throw down, and to build, and to plant,” he at the same time assigns
the reason—“Behold, I have put my words in thy mouth.”[912]
IV. If we advert to the apostles, they are certainly honoured with
many extraordinary characters. It is said that they are “the light of
the world,” and “the salt of the earth;”[913] that “he that heareth”
them “heareth Christ;”[914] that “whatsoever” they “shall bind on
earth shall be bound in heaven, and whatsoever” they “shall loose
on earth shall be loosed in heaven.”[915] But their very name shows
what degree of liberty they were allowed in their office; that if they
were apostles, they were not to declaim according to their own
pleasure, but to deliver with strict fidelity the commands of him who
had sent them. And the language of Christ is sufficiently clear, in
which he has defined their message by the following commission:
“Go ye, and teach all nations whatsoever I have commanded
you.”[916] He had even received and imposed on himself the same
law, in order that no one might refuse to submit to it. “My doctrine,”
says he, “is not mine, but his that sent me.”[917] He who was always
the eternal and only counsellor of the Father, and was constituted by
the Father the Lord and Master of all, yet because he sustained the
office of a teacher, prescribed, by his own example, the rule which
all ministers ought to follow in their teaching. The power of the
Church, therefore, is not unlimited, but subject to the word of the
Lord, and, as it were, included in it.
V. But whereas it has been a principle received in the Church from
the beginning, and ought to be admitted in the present day, that the
servants of God should teach nothing which they have not learned
from him, yet they have had different modes of receiving instruction
from him, according to the variety of different periods; and the
present mode differs from those which have preceded it. In the first
place, if the assertion of Christ be true, that “no man knoweth the
Father except the Son, and he to whomsoever the Son will reveal
him,”[918] it must always have been necessary for those who would
arrive at the knowledge of God, to be directed by that eternal
wisdom. For how could they have comprehended the mysteries of
God, or how could they have declared them, except by the teaching
of him, to whom alone the secrets of the Father are intimately
known? The saints in former ages, therefore, had no other
knowledge of God than what they obtained by beholding him in the
Son, as in a mirror. By this observation I mean that God never
manifested himself to man in any other way than by his Son, his
only wisdom, light, and truth. From this fountain Adam, Noah,
Abraham, Isaac, Jacob, and others, drew all the knowledge which
they possessed of heavenly doctrine; from this fountain the prophets
themselves drew all the celestial oracles which they spoke and
wrote. But this wisdom has not always manifested itself in the same
way. With the patriarchs God employed secret revelations; for the
confirmation of which, however, he at the same time added such
signs that they could not entertain the least doubt that it was God
who spake to them. What the patriarchs had received, they
transmitted from hand to hand to their posterity; for the Lord had
committed it to them on the express condition that they should so
propagate it. Succeeding generations, from the testimony of God in
their hearts, knew that what they heard was from heaven, and not
from the earth.
VI. But when it pleased God to raise up a more visible form of a
church, it was his will that his word should be committed to writing,
in order that the priests might derive from it whatever they would
communicate to the people, and that all the doctrine which should
be delivered might be examined by that rule. Therefore, after the
promulgation of the law, when the priests were commanded to teach
“out of the mouth of the Lord,” the meaning is, that they should
teach nothing extraneous, or different from that system of doctrine
which the Lord had comprised in the law; it was not lawful for them
to add to it or to diminish from it. Afterwards followed the prophets,
by whom God published new oracles, which were to be added to the
law; yet they were not so new but that they proceeded from the law,
and bore a relation to it. For in regard to doctrine, the prophets were
merely interpreters of the law, and added nothing to it except
prophecies of things to come. Except these, they brought forward
nothing but pure explication of the law. But because it pleased God
that there should be a more evident and copious doctrine, for the
better satisfaction of weak consciences, he directed the prophecies
also to be committed to writing, and to be accounted a part of his
word. To these likewise were added the histories, which were the
productions of the prophets, but composed under the dictation of
the Holy Spirit. I class the Psalms with the prophecies, because what
we attribute to the prophecies is common to the Psalms. That whole
body of Scripture, therefore, consisting of the Law, the Prophets, the
Psalms, and the Histories, was the word of God to the ancient
Church; and to this standard the priests and teachers, even to the
coming of Christ, were bound to conform their doctrine; nor was it
lawful for them to deviate either to the right hand or to the left,
because their office was wholly confined within these limits, that
they should answer the people from the mouth of God. And this may
be inferred from that remarkable passage of Malachi, where he
commands the Jews to remember the law, and to be attentive to it,
even till the publication of the gospel.[919] For in that injunction he
drives them off from all adventitious doctrines, and prohibits even
the smallest deviation from the path which Moses had faithfully
showed them. And it is for this reason that David so magnifies the
excellence of the law, and recounts so many of its praises; to
prevent the Jews from desiring any addition to it, since it contained
every thing necessary for them to know.
VII. But when, at length, the Wisdom of God was manifested in the
flesh, it openly declared to us all that the human mind is capable of
comprehending, or ought to think, concerning the heavenly Father.
Now, therefore, since Christ, the Sun of Righteousness, has shone
upon us, we enjoy the full splendour of Divine truth, resembling the
brightness of noonday, whereas the light enjoyed before was a kind
of twilight. For certainly the apostle intended to state no
unimportant fact when he said, that “God, who, at sundry times, and
in divers manners, spake in time past unto the fathers by the
prophets, hath in these last days spoken unto us by his Son;”[920] for
he here suggests, and even plainly declares, that God will not in
future, as in ages past, speak from time to time by one and another,
that he will not add prophecies to prophecies, or revelations to
revelations, but that he has completed all the branches of instruction
in his Son, so that this is the last and eternal testimony that we shall
have from him; for which reason this whole period of the New
Testament, from the appearance of Christ to us in the first
promulgation of his gospel, even to the day of judgment, is
designated as “the last time,” “the last times,” “the last days;” in
order that, being content with the perfection of the doctrine of
Christ, we may learn neither to invent any thing new or beyond it
ourselves, nor to receive any such thing from the invention of
others. It is not without cause, therefore, that the Father has given
us his Son by a peculiar privilege, and appointed him to be our
teacher, commanding attention to be paid to him, and not to any
mere man. He has recommended his tuition to us in few words,
when he says, “Hear ye him;”[921] but there is more weight and
energy in them than is commonly imagined; for they call us away
from all the instructions of men, and place us before him alone; they
command us to learn from him alone all the doctrine of salvation, to
depend upon him, to adhere to him, in short, as the words express,
to listen solely to his voice. And, indeed, what ought now to be
either expected or desired from man, when the Word of Life himself
has familiarly presented himself before us? It is rather necessary
that the mouths of all men should be shut, since he has once
spoken, in whom it has pleased the heavenly Father that all the
treasures of wisdom and knowledge should be hidden,[922] and has
spoken in a manner becoming the wisdom of God, in which there is
no imperfection, and the Messiah, who was expected to reveal all
things;[923] that is, has spoken in such a manner as to leave nothing
to be said by others after him.
VIII. Let us lay down this, then, as an undoubted axiom, that
nothing ought to be admitted in the Church as the word of God, but
what is contained first in the law and the prophets, and secondly in
the writings of the apostles, and that there is no other method of
teaching aright in the Church than according to the direction and
standard of that word. Hence we conclude, also, that the apostles
were allowed no more discretion than the prophets before them—
namely, to expound the ancient Scripture, and to show that the
things delivered in it were accomplished in Christ; but this they were
only to do from the Lord, that is to say, under the guidance and
dictation of the Spirit of Christ. For Christ limited their mission by
this condition, when he ordered them to go and teach, not the
fabrications of their own presumption, but whatsoever he had
commanded them.[924] And nothing could be more explicit than what
he said on another occasion: “Be not ye called Rabbi; for one is your
Master, even Christ.”[925] To fix this more deeply in their minds, he
repeats it twice in the same place. And because their weakness was
such that they were unable to comprehend the things which they
had heard and learned from the lips of their Master, the Spirit of
truth was promised to them, to lead them into the true
understanding of all things.[926] For that restriction is to be attentively
remarked, which assigns to the Holy Spirit the office of suggesting to
their minds all that Christ had before taught them with his mouth.
IX. Therefore Peter, who had been fully taught by his Master how far
his office extended, represents nothing as left for himself or others,
but to dispense the doctrine committed to them by God. “If any man
speak,” says he, “let him speak as the oracles of God;”[927] that is,
not with hesitation or uncertainty, like persons conscious of no
sufficient authority, but with the noble confidence which becomes a
servant of God furnished with his certain commission. What is this
but rejecting all the inventions of the human mind, from whatever
head they may proceed, in order that the pure word of God may be
taught and learned in the Church of believers? What is this but
removing all the decrees, or rather inventions of men, whatever be
their station, that the ordinances of God alone may be observed?
These are the spiritual “weapons, mighty through God to the pulling
down of strong-holds,” by which the faithful soldiers of God “cast
down imaginations, and every high thing that exalteth itself against
the knowledge of God, and bring into captivity every thought to the
obedience of Christ.”[928] This is the extent of the power with which
the pastors of the Church, by whatever name they may be
distinguished, ought to be invested;—that by the word of God they
may venture to do all things with confidence; may constrain all the
strength, glory, wisdom, and pride of the world to obey and submit
to his majesty; supported by his power, may govern all mankind,
from the highest to the lowest; may build up the house of Christ,
and subvert the house of Satan; may feed the sheep, and drive
away the wolves; may instruct and exhort the docile; may reprove,
rebuke, and restrain the rebellious and obstinate; may bind and
loose; may discharge their lightnings and thunders, if necessary; but
all in the word of God. Between the apostles and their successors,
however, there is, as I have stated, this difference—that the apostles
were the certain and authentic amanuenses of the Holy Spirit, and
therefore their writings are to be received as the oracles of God; but
succeeding ministers have no other office than to teach what is
revealed and recorded in the sacred Scriptures. We conclude, then,
that it is not now left to faithful ministers to frame any new doctrine,
but that it behoves them simply to adhere to the doctrine to which
God has made all subject, without any exception. In making this
observation, my design is to show, not only what is lawful to
individuals, but also to the universal Church. With respect to
particular persons, Paul had certainly been appointed by the Lord an
apostle to the Corinthians; yet he denies that he had any dominion
over their faith.[929] Who can now dare to arrogate to himself a
dominion which Paul testifies did not belong to him? If he had
sanctioned such a license of teaching, that whatever the pastor
delivered, he might require, as a matter of right, that the same
should be implicitly believed, he would never have recommended to
the same Corinthians such a regulation as this: “Let the prophets
speak two or three, and let the other judge. If any thing be revealed
to another that sitteth by, let the first hold his peace.”[930] For here
he exempted none, but made the authority of every one subject to
the control of the word of God. But the case of the universal Church,
it will be said, is different. I reply—Paul has obviated this objection in
another place, when he says that “faith cometh by hearing, and
hearing, by the word of God.”[931] But if it be the word of God alone
upon which faith is suspended, towards which it looks, and on which
it relies, I ask what is there left for the word of the whole world?
Here it will be impossible for any man to hesitate who has really
known what faith is. For it ought to rest on such firm ground as to
stand invincible and undismayed in opposition to Satan, to all the
machinations of hell, and to all the assaults of the world. This
stability we shall find in the word of God alone. Besides the reason
which we are here required to consider is of universal application—
that God denies to man the right of promulgating any new article of
faith, in order that he alone may be our Master in spiritual doctrine,
as he alone is true beyond all possibility of deceiving or being
deceived. This reason is no less applicable to the whole Church than
to every individual believer.
X. But if this power, which we have shown to belong to the Church,
be compared with that which has now for some ages past been
claimed over the people of God by the spiritual tyrants who have
falsely called themselves bishops and prelates of religion, there will
be no more resemblance than there is between Christ and Belial. It
is not my intention here to expose the shameful methods in which
they have exercised their tyranny: I shall only state the doctrine,
which they defend in the present age, not only by their writings, but
also by fire and sword. As they take it for granted that a universal
council is the true representative of the Church, having assumed this
principle, they at once determine, as beyond all doubt, that such
councils are under the immediate direction of the Holy Spirit, and
therefore cannot err. Now, as they themselves influence the councils,
and even constitute them, the fact is, that they assume to
themselves all that they contend for as belonging to the councils.
They wish our faith, therefore, to stand or fall at their pleasure, that
whatever they may have determined on one side or the other, may
be implicitly received by our minds as fully decided; so that if they
approve of any thing, we must approve of the same without any
hesitation; and if they condemn any thing, we must unite in the
condemnation of it. At the same time, according to their own
caprice, and in contempt of the word of God, they fabricate
doctrines which, for no other reason than this, they require to be
believed. For they acknowledge no man as a Christian, who does not
fully assent to all their dogmas, affirmative as well as negative, if not
with an explicit, at least with an implicit faith, because they pretend
that the Church has authority to make new articles of faith.
XI. First, let us hear by what arguments they prove this authority to
have been given to the Church; and then we shall see how far their
allegations respecting the Church contribute to support their cause.
The Church, they say, has excellent promises, that she is never to be
forsaken by Christ, her spouse, but will be led by his Spirit into all
truth.[932] But of the promises which they are accustomed to allege,
many are given no less to each believer in particular, than
collectively to the whole Church. For though the Lord was addressing
the twelve apostles when he said, “Lo, I am with you alway, even
unto the end of the world;”[933] and “I will pray the Father, and he
shall give you another comforter, even the Spirit of truth;”[934] he
made these promises not only to the apostles considered as a body,
but to every one of the number, and even to the other disciples
whom he had already received, or who were afterwards to be added
to them. Now, when they interpret these promises, replete with
peculiar consolation, in such a sense as if they were given to no
individual Christian, but only to the whole Church collectively, what is
this but depriving all Christians of the confidence with which such
promises ought to animate them? Here I do not deny that the whole
society of believers, being adorned with a manifold variety of gifts,
possesses a more ample and precious treasure of heavenly wisdom,
than each particular individual; nor do I intend that these things are
spoken of believers in common, as if they were all equally endued
with the spirit of understanding and doctrine; but we must not allow
the adversaries of Christ, in defence of a bad cause, to wrest the
Scripture to a sense which it was not intended to convey. Leaving
this remark, I freely acknowledge that the Lord is continually present
with his servants, and that he guides them by his Spirit; that this is
not a spirit of error, ignorance, falsehood, or darkness, but “the spirit
of wisdom, and revelation, and truth,” from whom they may certainly
learn “the things that are given to” them “of God,” or, in other
words, “may know what is the hope of his calling, and what the
riches of the glory of his inheritance in the saints.”[935] But as it is
nothing more than the first fruits, a kind of foretaste of that Spirit
that is enjoyed by believers in the present state, even by those of
them who are favoured with more excellent graces than others,
there remains nothing for them, but that, conscious of their
imbecility, they solicitously confine themselves within the limits of
the word of God; lest, if they proceed far by their own sense, they
should wander from the right way, in consequence of being not yet
fully enlightened by that Spirit, by whose teaching alone truth is
distinguished from falsehood. For all confess with Paul, that they
have not yet attained the mark; therefore they rather press on
towards daily improvement, than boast of perfection.[936]
XII. But they will object, that whatever is partially attributed to every
one of the saints, completely and perfectly belongs to the whole
Church. Notwithstanding the plausibility of this position, yet I deny it
to be true. I admit that God distributes the gifts of his Spirit by
measure to every member of his Church, in such a manner that
nothing necessary is wanting to the whole body, when those gifts
are bestowed in common. But the riches of the Church are always
such as to be very far from that consummate perfection boasted by
our adversaries. Yet the Church is not left destitute in any respect,
but that it always has what is sufficient; for the Lord knows what its
necessity requires. But to restrain it within the bounds of humility
and pious modesty, he bestows no more than he sees to be
expedient. Here, I know, they are accustomed to object, that the
Church has been “cleansed by the washing of water by the word,
that he might present it to himself a glorious Church, not having
spot, or wrinkle, or any such thing, but that it should be holy and
without blemish;”[937] and that for this reason it is called “the pillar
and ground of the truth.”[938] But the former of these passages rather
indicates what Christ is daily performing in his Church, than any
thing that he has already accomplished. For if he is daily sanctifying,
purifying, polishing, and cleansing his people, it must be evident that
they still have some spots and wrinkles, and that something is still
wanting to their sanctification. How vain and visionary is it to
imagine the Church already perfectly holy and immaculate, while all
its members are the subjects of corruption and impurity! It is true
that the Church is sanctified by Christ, but it is only the
commencement of their sanctification that is seen in the present
state; the end and perfect completion of it will be when Christ, the
Holy of Holies, shall fill it truly and entirely with his holiness. It is
likewise true that its spots and wrinkles are effaced, but in such a
manner that they are in a daily course of obliteration, till Christ at his
coming shall entirely efface all that remains. For, unless we admit
this, we must of necessity assert, with the Pelagians, that the
righteousness of believers is perfect in the present life, and with the
Cathari and Donatists, must allow no infirmity in the Church. The
other passage, as we have already seen, has a meaning totally
different from what they pretend. For after Paul had instructed
Timothy in the true nature of the office of a bishop, he says, “These
things I write unto thee, that thou mayest know how thou oughtest
to behave thyself in the house of God;” and to enforce his
conscientious attention to this object, he adds, that the Church itself
is “the pillar and ground of the truth.”[939] Now, what is the meaning
of this expression, but that the truth of God is preserved in the
Church, and that by the ministry of preaching? As in another place
he states, that Christ “gave some apostles, and some prophets, and
some evangelists, and some pastors and teachers, that we be no
more carried about with every wind of doctrine,” or deluded by men,
but that, being enlightened with the true knowledge of the Son of
God, we may “all come into the unity of the faith.”[940] The
preservation of the truth, therefore, from being extinguished in the
world, is in consequence of the Church being its faithful guardian, by
whose efforts and ministry it is maintained. But if this guardianship
consists in the ministry of the prophets and apostles, it follows that it
wholly depends on the faithful preservation of the purity of the word
of God.
XIII. And that the readers may better understand upon what point
this question principally turns, I will briefly state what our
adversaries require, and wherein we oppose them. When they assert
that the Church cannot err, their meaning is, as they themselves
explain it, that as it is governed by the Spirit of God, it may safely
proceed without the word; that whithersoever it goes, it can neither
think nor speak any thing that is not true; and, therefore, that if it
determine any thing beyond or beside the Divine word, the same is
to be considered in no other light than as a certain oracle of God. If
we grant the first point, that the Church cannot err in things
essential to salvation, our meaning is, that its security from error is
owing to its renouncing all its own wisdom, and submitting itself to
the Holy Spirit, to be taught by means of the word of God. This,
then, is the difference between us. They ascribe to the Church an
authority independent of the word; we maintain it to be annexed to
the word, and inseparable from it. And what is there surprising that
the spouse and disciple of Christ is subject to her Lord and Master,
so as to be assiduously and sedulously awaiting his commands and
instructions? For it is the order of a well regulated family, for the
wife to obey the command of the husband; it is the order of a well
disciplined school, that nothing be heard there but the instructions of
the master. Wherefore let not the Church be wise of itself, nor think
any thing of itself, but let it fix the boundary of its wisdom where
Christ has made an end of speaking. In this manner it will distrust all
the inventions of its own reason; but in those things in which it is
supported by the word of God, it will not waver with any distrust or
hesitation, but will rest upon it with strong certainty and unshaken
constancy. Thus confiding in the amplitude of the promises it has
received, it will have an excellent support for its faith, so that it
cannot doubt that the Holy Spirit, the best guide in the right way, is
always present with it; but, at the same time, it will remember what
advantage the Lord intends should be received from his Spirit. “The
Spirit,” says he, “whom I will send from the Father, will guide you
into all truth.” But how will this be done? Christ says, “He shall bring
all things to your remembrance, whatsoever I have said unto
you.”[941] He announces, therefore, that nothing more is to be
expected from his Spirit, than that he will enlighten our minds to
discover the truth of his doctrine. Wherefore it is very judiciously
observed by Chrysostom, that “many boast of the Holy Spirit; but in
those who speak from themselves this is a false pretence. As Christ
testified that he spake not of himself, because he spake from the law
and the prophets, so, if, under the name of the Spirit, any thing be
obtruded that is not contained in the gospel, let us not believe it. For
as Christ is the accomplishment of the law and the prophets, so is
the Spirit, of the gospel.” These are the words of Chrysostom. Now,
it is easy to infer how great is the error of our adversaries, who
boast of the Holy Spirit for no other purpose than to recommend,
under his name, doctrines strange and inconsistent with the word of
God, whereas it is his determination to be connected with the word
by an indissoluble bond; and this was declared by Christ when he
promised him to his Church. And so he is, in point of fact. The
sobriety which the Lord has once prescribed to his Church, he will
have to be perpetually observed; and he has forbidden the Church
to add any thing to his word, or to diminish any thing from it. This is
the inviolable decree of God and of the Holy Spirit, which our
adversaries endeavour to abrogate, when they pretend that the
Church is governed by the Spirit without the word.
XIV. Here, again, they cavil, that it was necessary for the Church to
add some things to the writings of the apostles, or at least for the
apostles themselves afterwards to supply in their discourses what
they had not so explicitly delivered in their writings, because Christ
declared to them, “I have yet many things to say unto you, but ye
cannot bear them now;”[942] and that these are the ordinances which
have been received by usage and custom without the Scripture. But
what effrontery is here betrayed! I confess that the disciples were
ignorant, and not very docile, when the Lord made this declaration
to them; but they were not so stupid, when they committed their
doctrine to writing, as to render it necessary for them afterwards to
supply in their discourses what they had from ignorance omitted in
their writings. But if, when they published their writings, they had
already been led by the Spirit into all truth, what hindered them
from comprising and leaving on record in those writings a perfect
system of evangelical doctrine? Let us grant our opponents,
however, what they ask: only let them enumerate those things which
required to be revealed, and are not contained in the apostolical
writings. If they dare to attempt this, I will reply in the words of
Augustine, “Where the Lord has been silent, which of us can say,
These things or those are intended; and if he dare to say so, how
will he prove it?” But why do I contend a point that is unnecessary?
For even children know that the apostolic writings, which these men
represent as incomplete and essentially deficient, contain the fruit of
that revelation which the Lord then promised them.
XV. What, say they, did not Christ place the doctrines and decrees of
the Church beyond all controversy, when he commanded him who
should dare to contradict it, to be regarded “as a heathen man and a
publican?”[943] In the first place, Christ in that text makes no mention
of doctrine, but only asserts the authority of the Church in
pronouncing censures for the correction of vices, in order that its
judgment may not be opposed by any who are admonished or
reproved. But leaving this remark, it is astonishing, that they have
no more modesty than to presume to boast of that passage. For
what will they extort from it, but that it is unlawful to despise the
consent of the Church, which never consents to any thing except the
truth of the word of God? The Church is to be heard, they say. Who
denies it? For it pronounces nothing but from the word of the Lord.
If they require any thing further, let them know that these words of
Christ afford them no support. Nor ought it to be esteemed too
contentious in me to insist so strenuously on this point—That it is not
lawful for the Church to invent any new doctrine, or to teach and
deliver, as of Divine authority, any thing more than the Lord has
revealed in his word. All persons of sound judgment perceive how
exceedingly dangerous it would be if so much power were once
granted to any man. For they see how wide a door is opened to the
scoffs and cavils of the impious, if we assert that the decisions of
men are to be received by Christians as articles of faith. It is also to
be remarked, that Christ spoke according to the established order of
his own time, and gave this name to the Sanhedrim, that his
disciples might learn afterwards to reverence the solemn assemblies
of the Church. And thus, on the principle of our adversaries, every
city and village would have an equal liberty to frame new articles of
faith.
XVI. The examples which they allege are nothing to the purpose.
They say that the baptism of infants arose, not so much from any
express command of Scripture, as from the decree of the Church. It
would be a most miserable asylum, if, in defence of infant baptism,
we were compelled to have recourse to the mere authority of the
Church; but it will be shown in another place, that the fact is very
different. So when they object, that the Scriptures nowhere affirm
what was pronounced in the Council of Nice, that the Son is of the
same substance with the Father, they do great injury to the fathers
of that council, as if they had presumptuously condemned Arius for
having refused to subscribe to their language, while he professed all
the doctrine which is contained in the writings of the prophets and
apostles. The word consubstantial, (ὁμοουσιος,) I confess, is not to
be found in the Scripture; but while, on the one hand, it is so often
affirmed that there is but one God, and, on the other, Christ is so
frequently called the true and eternal God, one with the Father, what
have the Nicene fathers done, but simply expressed the natural
sense of the Scripture, in declaring the Father and the Son to be of
one and the same substance? And Theodoret the historian states,
that Constantine the emperor opened that council with the following
preliminary address: “In disputes on Divine subjects, we are to
adhere to the doctrine of the Holy Spirit; the books of the
evangelists and apostles, with the oracles of the prophets, fully
reveal to us the will of God. Wherefore, laying aside all discord, let
us take the decision of all questions in debate from the words of the
Spirit.” There was no one at that time who opposed these holy
admonitions. No one objected, that the Church might add something
of its own, that the Spirit had not revealed every thing to the
apostles, or, at least, that they had not transmitted the whole to
posterity in writing, or any thing of the like nature. If what our
adversaries contend for be true, in the first place, Constantine acted
unjustly in depriving the Church of its power; and in the next place,
when none of the bishops rose to vindicate that power, their silence
was not to be excused from treachery, for on that occasion they
must have betrayed the rights of the Church. But from the statement
of Theodoret, that they readily received what was said by the
emperor, it is evident that this novel dogma of our adversaries was
at that time altogether unknown.
CHAPTER IX.
COUNCILS; THEIR AUTHORITY.

Though I should concede to our adversaries all the claims which


they set up on behalf of the Church, yet this would effect but little
towards the attainment of their object. For whatever is said
respecting the Church, they immediately transfer to the councils,
which they consider as representing the Church; and it may further
be affirmed, that their violent contentions for the power of the
Church, are with no other view than to ascribe all that they can
extort, to the Roman pontiff and his satellites. Before I enter on the
discussion of this question, it is necessary for me to premise two
brief observations. First, if in this chapter I am rather severe on our
opponents, it is not that I would show the ancient councils less
honour than they deserve. I venerate them from my heart, and wish
them to receive from all men the honour to which they are entitled;
but here some limits must be observed, that we may derogate
nothing from Christ. Now, it is the prerogative of Christ to preside
over all councils, and to have no mortal man associated with him in
that dignity. But I maintain, that he really presides only where he
governs the whole assembly by his word and Spirit. Secondly, when
I attribute to the councils less than our adversaries require, I am not
induced to do this from any fear that the councils would favour their
cause and oppose ours. For as we are sufficiently armed by the word
of the Lord, and need not seek any further assistance for the
complete establishment of our doctrine, and the total subversion of
Popery, so, on the other hand, if it were necessary, the ancient
councils would furnish us in a great measure with sufficient
arguments for both these objects.
II. Let us now come to the subject itself. If it be inquired what is the
authority of councils according to the Scriptures, there is no promise
more ample or explicit than this declaration of Christ: “Where two or
three are gathered together in my name, there am I in the midst of
them.”[944] But this belongs no less to every particular congregation
than to a general council. The main stress of the question, however,
does not lie in this, but in the annexed condition,—that Christ will be
in the midst of a council, then, and then only, when it is assembled
in his name. Wherefore, though our adversaries mention councils of
bishops a thousand times, they will gain but little ground; nor will
they prevail upon us to believe what they pretend,—that such
councils are directed by the Holy Spirit,—till it shall have been
proved, that they are assembled in the name of Christ. For it is
equally as possible for impious and unfaithful bishops to conspire
against Christ, as for pious and upright bishops to assemble together
in his name. Of this we have ample proof in numerous decrees
which have been issued by such councils; as will be seen in the
course of this discussion. At present I only reply in one word, that
the promise of Christ is exclusively restricted to those who “are
gathered together in his name.” Let us, therefore, define wherein
this consists. I deny that they are assembled in the name of Christ,
who, rejecting the command of God, which prohibits any diminution
of his word, or the smallest addition to it,[945] determine every thing
according to their own pleasure; who, not content with the oracles
of the Scripture, which constitute the only rule of perfect wisdom,
invent something new out of their own heads. Since Christ has not
promised to be present in all councils, but has added a particular
mark to discriminate true and legitimate councils from others, it
certainly behoves us by no means to neglect this distinction. This
was the covenant which God anciently made with the Levitical
priests, that they should teach their people from his mouth;[946] he
always required the same of the prophets; and we see that a similar
law was imposed upon the apostles. Those who violate this
covenant, God neither dignifies with the honour of the priesthood,
nor invests with any authority. Let our adversaries solve this
difficulty, if they wish me to submit my faith to the decrees of men,
independently of the word of God.
III. For their supposition, that no truth remains in the Church, unless
it be found among the pastors, and that the Church itself stands, no
longer than it appears in general councils, is very far from having
been always correct, if the prophets have left us any authentic
records of their times. In the days of Isaiah, there was a Church at
Jerusalem, which God had not yet forsaken: nevertheless he speaks
of the priests in the following manner: “His watchmen are blind;
they are all ignorant; they are all dumb dogs, they cannot bark;
sleeping, lying down, loving to slumber: they are shepherds that
cannot understand: they all look to their own way, every one for his
gain, from his quarter.”[947]—Hosea speaks in a similar manner: “The
watchman of Ephraim was with my God; but the prophet is a snare
of a fowler in all his ways, and hatred in the house of his God.”[948]
By thus ironically connecting them with God, he shows that their
priesthood was a vain pretence. The Church continued also to the
time of Jeremiah. Let us hear what he says of the pastors. “From the
prophet even unto the priest, every one dealeth falsely.”[949] Again:
“the prophets prophesy lies in my name; I sent them not, neither
have I commanded them.”[950] And to avoid too much prolixity in
reciting his words, I would recommend my readers to peruse the
whole of the twenty-third and fortieth chapters. Nor were the same
persons treated with less severity by Ezekiel: “There is a conspiracy
of her prophets in the midst thereof, like a roaring lion ravening the
prey; they have devoured souls; they have taken the treasure and
precious things; they have made her many widows in the midst
thereof. Her priests have violated my law, and have profaned mine
holy things; they have put no difference between the holy and
profane. Her prophets have daubed them with untempered mortar,
seeing vanity, and divining lies unto them, saying, Thus saith the
Lord God, when the Lord hath not spoken.”[951] Similar complaints
abound in all the prophets, so that there is nothing of more frequent
recurrence.
IV. But it will be said, though such may have been the case among
the Jews, our age is exempt from so great a calamity. I sincerely
wish that it were so; but the Holy Spirit has denounced that the
event would be very different. The language of Peter is clear: “There
were false prophets also among the people, even as there shall be
false teachers among you, who privily shall bring in damnable
heresies.”[952] Observe how he declares that danger will arise, not
from the common people, but from those who will assume to
themselves the name of pastors and teachers. Besides, how often is
it predicted by Christ and his apostles, that the greatest dangers
would be brought upon the Church by its pastors![953] Paul expressly
denounces that Antichrist will “sit in the temple of God;”[954] by
which he signifies, that the dreadful calamity of which he speaks,
will arise from the very persons who will sit as pastors in the Church.
And in another place, he shows that the commencement of the
mischief was then near at hand. For addressing the bishops of the
Church of Ephesus, he says, “I know this, that after my departing
shall grievous wolves enter in among you, not sparing the flock; also
of your own selves shall men arise, speaking perverse things, to
draw away disciples after them.”[955] If the pastors could so
degenerate in a very short space of time, what enormous corruption
might be introduced among them in a long series of years! And not
to occupy much room with an enumeration, we are taught by the
examples of almost all ages, that neither is the truth always
maintained in the bosom of the pastors, nor the safety of the Church
dependent on their stability. They ought, indeed, to be the guardians
and defenders of the peace and safety of the Church, for the
preservation of which they are appointed; but it is one thing to
perform a duty which we owe, and another, to owe a duty which we
do not perform.
V. Let no person conclude from what I have said, that I am inclined
on all occasions, and without any discrimination, to weaken the
authority of pastors, and bring it into contempt. I only mean to
suggest the necessity of discriminating between some pastors and
others, that we may not immediately consider persons as pastors
because they bear that title. But the pope and all his bishops, for no
other reason but because they are called pastors, casting off all
obedience to the word of God, disturb and confound every thing at
their own pleasure; while they labour to persuade us that it is
impossible for them to be destitute of the light of truth, that the
Spirit of God perpetually resides in them, and that with them the
Church lives and dies. As though the Lord had now no judgments, to
inflict upon the world, in the present day, the same kind of
punishment, with which he once visited the ingratitude of his ancient
people;[956] namely, to smite the pastors with astonishment,
madness, and blindness. And such is their extreme stupidity, they
are not aware that they are acting the same part which was acted by
those who resisted the word of the Lord in ancient times. For thus
the enemies of Jeremiah fortified themselves in opposition to the
truth: “Come, and let us devise devices against Jeremiah; for the law
shall not perish from the priest, nor counsel from the wise, nor the
word from the prophet.”[957]
VI. Hence it is easy to reply to another plea in behalf of general
councils. That a true Church existed among the Jews in the time of
the prophets, cannot be denied. But if a general council of the
priests had been convened, what appearance of a Church would
such a council have displayed? We hear what God denounces, not
against two or three of them, but against the whole body: “The
priests shall be astonished, and the prophets shall wonder.”[958]
Again: “The law shall perish from the priest, and counsel from the
ancients.”[959] Again: “Night shall be unto you, that ye shall not have
a vision; and it shall be dark unto you, that ye shall not divine; and
the sun shall go down over the prophets, and the day shall be dark
over them.”[960] Now, if these priests and prophets had all been
collected together, what spirit would have presided in their
assembly? This is remarkably exemplified in the council convoked by
Ahab. Four hundred prophets were present. But because they were
assembled with no other intention than to flatter that impious
monarch, Satan was sent by the Lord to be a lying spirit in all their
mouths.[961] There the truth was rejected with one consent; Micaiah
was condemned as a heretic, beaten, and cast into prison. Jeremiah
received the same treatment, and other prophets experienced
similar injustice.
VII. But one example, which is more memorable than the rest, may
suffice as a specimen of all. In the council which the chief priests
and Pharisees convened at Jerusalem against Christ, what was there
wanting in point of external form? For if there had then been no
Church at Jerusalem, Christ would never have united in their
sacrifices and other ceremonies. A solemn summons was issued; the
high priest presided; all the priests attended; yet there Christ was
condemned, and his doctrine rejected. This act proves that the
Church was not contained in that council. But, it will be said, there is
no danger of such a circumstance happening to us. Who has assured
us of this? For to be too confident in a matter of such great
importance, is culpable stupidity. But while the Spirit has expressly
predicted, by the mouth of Paul, that there shall come an apostasy,
which cannot take place without the pastors being the first to revolt
from God,[962] why do we wilfully shut our eyes to our own ruin?
Wherefore it is by no means to be conceded, that the Church
consists in the assembly of the pastors, respecting whom God has
nowhere promised that they should always be good, but, on the
contrary, has denounced that they would sometimes be wicked.
Now, when he warns us of a danger, his design is to make us more
cautious.
VIII. What, then, it will be said, shall the decisions of councils have
no authority? Yes, certainly; for I am not contending that all councils
ought to be condemned, or that all their acts ought to be rescinded
and cancelled at once. Still I shall be told, that I degrade their
authority, so as to leave it to the option of every individual to receive
or reject whatever a council shall have determined. By no means;
but whenever a decree of any council is brought forward, I would
wish, first, that a diligent inquiry should be made, at what time, for
what cause, and with what design it was held, and what kind of
persons were present; secondly, that the subject discussed in it
should be examined by the standard of the Scripture; and this in
such a manner that the determination should have its weight, and
be considered as a precedent or case formerly decided, but that it
should not preclude the examination which I have mentioned. I
sincerely wish that every person would observe the method
recommended by Augustine in his third book against Maximinus. For,
with a view to silence the contentions of that heretic respecting the
decrees of councils, he says, “I ought not to object to you the
Council of Nice, nor ought you to object to me the Council of
Ariminum, to preclude each other’s judgment by a previous decision.
I am not bound by the authority of the latter, nor you by that of the
former. Let cause contend with cause, and argument with argument,
on the ground of scriptural authorities, which exclusively belong to
neither party, but are common to both.” The consequence of such a
mode of proceeding would be, that councils would retain all the
majesty which is due to them, while at the same time the Scripture
would hold the preëminence, so that every thing would be subject to
its standard. Upon this principle, those ancient councils, such as the
Council of Nice, of Constantinople, the first of Ephesus, that of
Chalcedon, and others like them, which were held for the
condemnation of errors, we cheerfully receive and reverence as
sacred, as far as respects the articles of faith which they have
defended; for they contain nothing but the pure and natural
interpretation of the Scripture, which the holy fathers, with spiritual
prudence, applied to the discomfiture of the enemies of religion who
arose in those days. In some of the succeeding councils, likewise,
we discover a true zeal for piety, and evident proofs of sense,
learning, and prudence. But as the progress of the world is generally
from worse to worse, it is easy to see, from the more recent
councils, how much the Church has gradually degenerated from the
purity of that golden age. Even in these more corrupt ages, I doubt
not, the councils have been partly composed of some bishops of a
better character; but the same observation may be applied to their
acts, which was formerly made in a way of complaint against the
decrees of the Roman senate, by the senators themselves. Where
opinions prevail according to their number, and not according to the
weight of argument by which they are supported, the better part of
the assembly must of necessity be frequently overcome by the
majority. And councils have certainly issued many impious decrees.
It is unnecessary here to produce particular examples, as well
because this would carry us to too great a length, as because it has
already been done by others with a diligence which scarcely admits
of any addition.
IX. Now, what need is there to enumerate the repugnances between
councils and councils, and how decrees passed by one have been
rescinded by another? Here it must not be alleged, that where there
is such variance between two councils, one or the other is not
legitimate. For how shall we determine this? The only way I know, is
to ascertain from the Scriptures that its decrees are not orthodox;
for there is no other certain rule of decision. It is now about nine
hundred years ago, that the Council of Constantinople, assembled
under the emperor Leo, decreed that all images placed in churches
should be thrown down and broken in pieces. Soon after, the Council
of Nice, which the empress Irene convened in opposition to the
former, decreed that they should be restored. Which of these two
shall we acknowledge as a legitimate council? This character has
generally been attributed to the latter, which gave images a place in
the Churches. But Augustine declares that this cannot be done
without imminent danger of idolatry. Epiphanius, a more ancient
writer, expresses himself in terms of much greater severity; he says
that it is abominable wickedness for images to be seen in the
temples of Christians. Would the fathers who speak in this manner
approve of that council, if they were now living? But if the accounts
of historians be true, and credit be given to the acts themselves,
that council not only admitted of images, but determined that they
were to be worshipped. Now, it is evident that such a decree must
have originated from Satan. What shall we say to their perversions
and mutilations of the Scripture, which demonstrate that they held it
all in contempt, as I have already proved? We shall never be able to
discriminate between the numerous councils, which dissent from and
contradict each other, unless we examine them all by the word of
God, which is the universal standard for men and angels. On this
ground, we reject the second Council of Ephesus, and receive the
Council of Chalcedon, because the latter council condemned the
impiety of Eutyches, which the former had sanctioned. This
judgment of the Council of Chalcedon was formed from the
Scriptures by holy men, whom we imitate in forming our judgment,
as the word of God which enlightened them continues to give light
to us. Now, let the Romanists go and boast, as they are accustomed
to do, that the Holy Spirit is inseparably attached to their councils.
X. Even in the earliest and purest councils, however, there is
something to complain of—either that the bishops who composed
them, though men of learning and prudence, being perplexed with
the subjects immediately before them, did not extend their views to
many other things; or that while they were occupied with more
weighty and serious concerns, things of inferior moment escaped
their notice; or merely that, being men, they were liable to
ignorance and error; or that they were sometimes hurried into
precipitancy by the violence of their passions. Of the truth of the last
observation, which seems the severest of all, there is a remarkable
example in the Council of Nice; the dignity of which has been
universally and justly held in the highest veneration. For though the
principal article of our faith was endangered, and they had to
contend with Arius, the enemy of it, who was there in readiness for
the contest,—though it was of the greatest importance that harmony
should be maintained among those who came with a design to
confute the error of Arius,—notwithstanding that, careless of such
great dangers, forgetful of gravity, modesty, and every thing like
good manners, dropping the controversy between them, as if they
had assembled with an express view to the gratification of Arius,
they began to counteract themselves with intestine dissensions, and
to direct against each other the pen which ought to have been
employed against Arius. The foulest accusations were heard,
defamatory libels were circulated, and there would have been no
end of the contentions till they had murdered one another, if it had
not been for the interference of the emperor Constantine, who
protested that a scrutiny into their lives was a thing beyond his
cognizance, and repressed this intemperate conduct with praise
rather than with censure. In how many instances is it probable that
errors were committed by other succeeding councils? Nor does this
require any long proof; for whoever peruses their acts, will discover
many infirmities, not to mention any thing worse.
XI. And Leo, the Roman pontiff, hesitates not to bring a charge of
ambition and inconsiderate temerity against the Council of
Chalcedon, which he at the same time acknowledges to have been
orthodox in points of doctrine. He does not deny it to have been a
legitimate council, but he unequivocally asserts that it was possible
for it to err. It may be thought, perhaps, that I betray a want of
judgment in taking pains to point out such errors; since our
adversaries confess that councils might err in things not essential to
salvation. This labour, however, is not unnecessary. For though they
find themselves obliged to confess this in words, yet when they
obtrude upon us the decision of every council on every subject,
without any discrimination, as an oracle of the Holy Spirit, they
require of us, in fact, more than they had first assumed. What is the
language of such conduct, but that councils cannot err, or that, if
they do err, it is unlawful for us to discover the truth, or to refuse
assent to errors? And I intend to draw no other conclusion from
these facts, than that the Holy Spirit governed pious and Christian
councils in such a manner, as at the same time to permit them to
betray something of human infirmity, that we might not place too
much confidence in men. This sentiment is far more favourable than
that of Gregory of Nazianzum, “that he never saw a good end of any
council.” For he who affirms that all without exception terminated ill,
leaves them but little authority. It is unnecessary here to take
distinct notice of provincial councils, since it is easy to judge from
the general councils, what authority they ought to possess in
framing articles of faith, and receiving whatever kind of doctrine they
pleased.
XII. But our Romanists, when they find all the supports of reason fail
them in the defence of their cause, have recourse to that last and
wretched subterfuge—That although the persons themselves betray
the greatest stupidity in their understandings and pleas, and act
from the most iniquitous motives and designs, still the word of God
remains, which commands us to obey our governors.[963] But what if
I deny that such persons are our governors? For they ought not to
arrogate to themselves more than belonged to Joshua, who was a
prophet of the Lord and an excellent pastor. Now, let us hear with
what language he was inaugurated into his office by the Lord: “This
book of the law shall not depart out of thy mouth; but thou shalt
meditate therein day and night: turn not from it to the right hand or
to the left, that thou mayest prosper whithersoever thou goest.”[964]
We shall consider them as our spiritual governors, therefore, who
deviate not from the word of God, either to the right hand or to the
left. If the doctrine of all pastors ought to be received without any
hesitation, why have we such frequent and earnest admonitions
from the mouth of the Lord himself, not to listen to the speeches of
false prophets? “Hearken not,” says he by Jeremiah, “unto the words
of the prophets that prophesy unto you; they make you vain; they
speak a vision of their own hearts, and not out of the mouth of the
Lord.”[965] Again: “Beware of false prophets, which come to you in
sheep’s clothing, but inwardly they are ravening wolves.”[966] The
exhortation given us by John would also have been useless: “Try the
spirits, whether they are of God;”[967] though from this examination
the very angels are not exempted, much less Satan with all his
falsehoods. How are we to understand this caution of our Lord? “If
the blind lead the blind, both shall fall into the ditch.”[968] Does it not
sufficiently declare, that it is of the highest importance what kind of
pastors are heard, and that they are not all entitled to the same
attention? Wherefore there is no reason why they should overawe us
with their titles, to make us partakers of their blindness, while we
see, on the contrary, that the Lord has taken peculiar care to deter
us from suffering ourselves to be seduced by the error of other men,
under whatever mask or name it may be concealed. For if the
answer of Christ be true, all blind guides, whether they are
denominated priests, prelates, or pontiffs, can do nothing but
precipitate their followers into the same ruin with themselves.
Impressed, therefore, by these warnings, both of precepts and of
examples, no names of pastors, bishops, or councils, which are as
capable of being falsely claimed as rightly assumed, ought ever to
prevent us from examining all the spirits by the rule of the Divine
word, in order to “try whether they are of God.”
XIII. Having proved that the Church has received no power to frame
any new doctrine, let us now speak of the power which our
opponents attribute to it in the interpretation of the Scripture. We
have not the least objection to admit, that if a controversy arise
respecting any doctrine, there is no better or more certain remedy
than to assemble a council of true bishops, in which the
controverted doctrine may be discussed. For such a decision, formed
by the common consent of the pastors of the Churches, after an
invocation of the Spirit of Christ, will have far greater weight, than if
every one of them separately were to maintain it in preaching to his
people, or if it were the result of a private conference between a few
individuals. Besides, when bishops are collected in one assembly,
they deliberate together with greater advantage on what they ought
to teach, and the manner in which their instructions should be
conveyed, so as to guard against offence arising from diversity. In
the third place, Paul prescribes this method of determining
respecting doctrines. For while he attributes to every distinct Church
a power “to judge,”[969] he shows what ought to be the order of
proceeding in more important cases; namely, that the Churches
should undertake the common cognizance of them. And so the
dictate of piety itself teaches us, that if any one disturb the Church
with a new doctrine, and the matter be carried so far as to cause
danger of a more grievous dissension, the Churches should first
assemble, should examine the question proposed to them, and after
a sufficient discussion of it, should announce a decision taken from
the Scriptures, which would put an end to all doubt among the
people, and shut the mouths of refractory and ambitious persons, so
as to check their further presumption. Thus, when Arius arose, the
Council of Nice was assembled, and by its authority defeated the
pernicious attempts of that impious man, restored peace to the
Churches which he had disturbed, and asserted the eternal deity of
Christ in opposition to his sacrilegious dogma. Some time after, when
Eunomius and Macedonius raised new contentions, their frenzy was
opposed with a similar remedy by the Council of Constantinople. The
impiety of Nestorius was condemned in the first Council of Ephesus.
In short, this has been the ordinary method of the Church from the
beginning, for the preservation of unity, whenever Satan has begun
to make any attempt against it. But let it be remembered, that
neither every age, nor every place, can produce an Athanasius, a
Basil, a Cyril, and other such champions of the true doctrine, as the
Lord raised up at those periods. Let it also be recollected what
happened at the second Council of Ephesus, in which the heresy of
Eutyches prevailed. Flavianus, a bishop of irreproachable memory,
was banished, together with other pious men, and many similar
enormities were committed, because it was Dioscorus, a factious and
ill-disposed man, and not the Spirit of the Lord, that presided in that
council. But that council, it will be said, was not the Church. I admit
it: for I am firmly persuaded of this, that the truth is not extinct in
the Church, though it may be oppressed by one council, but that it is
wonderfully preserved by the Lord, to arise and triumph again in his
own time. But I deny it to be an invariable rule, that every
interpretation which may have been approved by a council is the
true and certain sense of the Scripture.
XIV. But the Romanists have a further design in maintaining that
councils possess the power of interpreting the Scripture, and that
without appeal. For it is a false pretence, when every thing that has
been determined in councils is called an interpretation of the
Scripture. Of purgatory, the intercession of saints, auricular
confession, and similar fooleries, the Scriptures contain not a single
syllable. But, because all these things have been sanctioned by the
authority of councils, or, to speak more correctly, have been
admitted into the general belief and practice, therefore every one of
them is to be taken for an interpretation of Scripture. And not only
so; but if a council determine in direct opposition to the Scripture, it
will still be called an interpretation of it. Christ commands all to drink
of the cup which he presents to them in the sacred supper.[970] The
Council of Constance prohibited it to be given to the laity, and
determined that none but the priest should drink of it. Yet this,
which is so diametrically repugnant to the institution of Christ, they
wish us to receive as an interpretation of it. Paul calls “forbidding to
marry” a “doctrine of devils;”[971] and the Holy Spirit, in another
place, pronounces that “marriage is honourable in all, and the bed
undefiled.”[972] The prohibition, which they have since denounced, of
the marriage of priests, they wish us to consider as the true and
natural interpretation of the Scriptures, though nothing can be
imagined more repugnant to it. If any one dare to open his mouth to
the contrary, he is condemned as a heretic, because the
determination of the Church is without appeal, and the truth of its
interpretation cannot be doubted without impiety. What further
requires to be urged against such consummate effrontery? The mere
exhibition of it is a sufficient refutation. Their pretensions to confirm
the Scripture by the authority of the Church, I purposely pass over.
To subject the oracles of God to the authority of men, so as to make
their validity dependent on human approbation, is a blasphemy
unworthy of being mentioned; beside which, I have touched on this
subject already. I will only ask them one question: If the authority of
the Scripture be founded on the approbation of the Church, what
decree of any council can they allege to this point? I believe, none at
all. Why, then, did Arius suffer himself to be vanquished at Nice by
testimonies adduced from the Gospel of John? According to the
argument of our opponents, he was at liberty to reject them, as not
having yet received the approbation of any general council. They
allege an ancient catalogue, which is called the Canon of Scripture,
and which they say proceeded from the decision of the Church. I ask
them again, in what council that canon was composed. To this they
can make no reply. Yet I would wish to be further informed, what
kind of a canon they suppose it to be. For I see that the ancient
writers were not fully agreed respecting it. And if any weight be
attached to the testimony of Jerome, the two books of the
Maccabees, the history of Tobit, Ecclesiasticus, and other books, will
be considered as apocryphal; to which our opponents will by no
means consent.

You might also like