Programming Python: Computation Using
Programming Python: Computation Using
Computation and
John V. Guttag
Cambridge, Massachusetts
London, England
CONTENTS
PREFACE xiii
xv
ACKNOWLEDGMENTS
1 GETTING STARTED 1
2 INTRODUCTION TO PYTHON 7
2.1.3 IDLE 13
2.2 14
Branching Programs
16
2.3 Strings and Input
2.3.1 18
Input
2.4 Iteration 18
3.2 For 23
Loops
3.5 32
Newton-Raphson
ABSTRACTION 34
4 FUNCTIONS, SCOPING, and
Functions and 35
4.1 Scoping
Values 36
4.1.2 Keyword Arguments and Default
4.1.3 37
Scoping
41
4.2 Specifications
4.3 Recursion 44
4.3.2 Palindromes 48
4.5 Modules 51
4.6 Files 53
5 STRUCTURED TYPES, MUTABILITY, AND HIGHER-ORDER FUNCTIONS.. 56
5.1 Tuples 56
5.2.1 Cloning 63
5.5 Dictionaries 67
6.1 Testing 70
6.2 Debugging 76
7.3 Assertions 90
8.2 Inheritance 99
261
18.3 Dynamic Programming and Divide-and-Conquer
19.8 286
Wrapping Up
287
PYTHON 2.7 QUICK REFERENCE
INDEX 289