Synopses & Reviews
If you want to learn how to program, working with Python is an excellent way to start. This hands-on guide takes you through the language one step at a time, beginning with basic programming concepts before moving on to functions, recursion, data structures, and object-oriented design.
Through exercises in each chapter, youll try out programming concepts as you learn them. Think Python is ideal for students at the high school or college level, as well as self-learners, home-schooled students, and professionals who need to learn programming basics.
- Start with the basics, including language syntax and semantics
- Get a clear definition of each programming concept
- Learn values, variables, statements, functions, and data structures in a logical progression
- Discover how to work with files and databases
- Understand objects, methods, and object-oriented programming
- Use debugging techniques to fix syntax, runtime, and semantic errors
- Explore interface design, data structures, and GUI-based programs through case studies
Synopsis
Think Python is an introduction to Python programming for students with no programming experience. It starts with the most basic concepts of programming, and is carefully designed to define all terms when they are first used and to develop each new concept in a logical progression. Larger pieces, like recursion and object-oriented programming are divided into a sequence of smaller steps and introduced over the course of several chapters.
About the Author
Allen Downey is an Associate Professor of Computer Science at the Olin College of Engineering. He has taught computer science at Wellesley College, Colby College and U.C. Berkeley. He has a Ph.D. in Computer Science from U.C. Berkeley and Masters and Bachelors degrees from MIT.
Table of Contents
Preface; The Strange History of This Book; Acknowledgments; Contributor List; Chapter 1: The Way of the Program; 1.1 The Python Programming Language; 1.2 What Is a Program?; 1.3 What Is Debugging?; 1.4 Syntax Errors; 1.5 Runtime Errors; 1.6 Semantic Errors; 1.7 Experimental Debugging; 1.8 Formal and Natural Languages; 1.9 The First Program; 1.10 Debugging; 1.11 Glossary; 1.12 Exercises; Chapter 2: Variables, Expressions, and Statements; 2.1 Values and Types; 2.2 Variables; 2.3 Variable Names and Keywords; 2.4 Operators and Operands; 2.5 Expressions and Statements; 2.6 Interactive Mode and Script Mode; 2.7 Order of Operations; 2.8 String Operations; 2.9 Comments; 2.10 Debugging; 2.11 Glossary; 2.12 Exercises; Chapter 3: Functions; 3.1 Function Calls; 3.2 Type Conversion Functions; 3.3 Math Functions; 3.4 Composition; 3.5 Adding New Functions; 3.6 Definitions and Uses; 3.7 Flow of Execution; 3.8 Parameters and Arguments; 3.9 Variables and Parameters Are Local; 3.10 Stack Diagrams; 3.11 Fruitful Functions and Void Functions; 3.12 Why Functions?; 3.13 Importing with from; 3.14 Debugging; 3.15 Glossary; 3.16 Exercises; Chapter 4: Case Study: Interface Design; 4.1 TurtleWorld; 4.2 Simple Repetition; 4.3 Exercises; 4.4 Encapsulation; 4.5 Generalization; 4.6 Interface Design; 4.7 Refactoring; 4.8 A Development Plan; 4.9 Docstring; 4.10 Debugging; 4.11 Glossary; 4.12 Exercises; Chapter 5: Conditionals and Recursion; 5.1 Modulus Operator; 5.2 Boolean Expressions; 5.3 Logical Operators; 5.4 Conditional Execution; 5.5 Alternative Execution; 5.6 Chained Conditionals; 5.7 Nested Conditionals; 5.8 Recursion; 5.9 Stack Diagrams for Recursive Functions; 5.10 Infinite Recursion; 5.11 Keyboard Input; 5.12 Debugging; 5.13 Glossary; 5.14 Exercises; Chapter 6: Fruitful Functions; 6.1 Return Values; 6.2 Incremental Development; 6.3 Composition; 6.4 Boolean Functions; 6.5 More Recursion; 6.6 Leap of Faith; 6.7 One More Example; 6.8 Checking Types; 6.9 Debugging; 6.10 Glossary; 6.11 Exercises; Chapter 7: Iteration; 7.1 Multiple Assignment; 7.2 Updating Variables; 7.3 The while Statement; 7.4 break; 7.5 Square Roots; 7.6 Algorithms; 7.7 Debugging; 7.8 Glossary; 7.9 Exercises; Chapter 8: Strings; 8.1 A String Is a Sequence; 8.2 len; 8.3 Traversal with a for Loop; 8.4 String Slices; 8.5 Strings Are Immutable; 8.6 Searching; 8.7 Looping and Counting; 8.8 String Methods; 8.9 The in Operator; 8.10 String Comparison; 8.11 Debugging; 8.12 Glossary; 8.13 Exercises; Chapter 9: Case Study: Word Play; 9.1 Reading Word Lists; 9.2 Exercises; 9.3 Search; 9.4 Looping with Indices; 9.5 Debugging; 9.6 Glossary; 9.7 Exercises; Chapter 10: Lists; 10.1 A List Is a Sequence; 10.2 Lists Are Mutable; 10.3 Traversing a List; 10.4 List Operations; 10.5 List Slices; 10.6 List Methods; 10.7 Map, Filter, and Reduce; 10.8 Deleting Elements; 10.9 Lists and Strings; 10.10 Objects and Values; 10.11 Aliasing; 10.12 List Arguments; 10.13 Debugging; 10.14 Glossary; 10.15 Exercises; Chapter 11: Dictionaries; 11.1 Dictionary as a Set of Counters; 11.2 Looping and Dictionaries; 11.3 Reverse Lookup; 11.4 Dictionaries and Lists; 11.5 Memos; 11.6 Global Variables; 11.7 Long Integers; 11.8 Debugging; 11.9 Glossary; 11.10 Exercises; Chapter 12: Tuples; 12.1 Tuples Are Immutable; 12.2 Tuple Assignment; 12.3 Tuples as Return Values; 12.4 Variable-Length Argument Tuples; 12.5 Lists and Tuples; 12.6 Dictionaries and Tuples; 12.7 Comparing Tuples; 12.8 Sequences of Sequences; 12.9 Debugging; 12.10 Glossary; 12.11 Exercises; Chapter 13: Case Study: Data Structure Selection; 13.1 Word Frequency Analysis; 13.2 Random Numbers; 13.3 Word Histogram; 13.4 Most Common Words; 13.5 Optional Parameters; 13.6 Dictionary Subtraction; 13.7 Random Words; 13.8 Markov Analysis; 13.9 Data Structures; 13.10 Debugging; 13.11 Glossary; 13.12 Exercises; Chapter 14: Files; 14.1 Persistence; 14.2 Reading and Writing; 14.3 Format Operator; 14.4 Filenames and Paths; 14.5 Catching Exceptions; 14.6 Databases; 14.7 Pickling; 14.8 Pipes; 14.9 Writing Modules; 14.10 Debugging; 14.11 Glossary; 14.12 Exercises; Chapter 15: Classes and Objects; 15.1 User-Defined Types; 15.2 Attributes; 15.3 Rectangles; 15.4 Instances as Return Values; 15.5 Objects Are Mutable; 15.6 Copying; 15.7 Debugging; 15.8 Glossary; 15.9 Exercises; Chapter 16: Classes and Functions; 16.1 Time; 16.2 Pure Functions; 16.3 Modifiers; 16.4 Prototyping Versus Planning; 16.5 Debugging; 16.6 Glossary; 16.7 Exercises; Chapter 17: Classes and Methods; 17.1 Object-Oriented Features; 17.2 Printing Objects; 17.3 Another Example; 17.4 A More Complicated Example; 17.5 The init Method; 17.6 The __str__ Method; 17.7 Operator Overloading; 17.8 Type-Based Dispatch; 17.9 Polymorphism; 17.10 Debugging; 17.11 Interface and Implementation; 17.12 Glossary; 17.13 Exercises; Chapter 18: Inheritance; 18.1 Card Objects; 18.2 Class Attributes; 18.3 Comparing Cards; 18.4 Decks; 18.5 Printing the Deck; 18.6 Add, Remove, Shuffle, and Sort; 18.7 Inheritance; 18.8 Class Diagrams; 18.9 Debugging; 18.10 Data Encapsulation; 18.11 Glossary; 18.12 Exercises; Chapter 19: Case Study: Tkinter; 19.1 GUI; 19.2 Buttons and Callbacks; 19.3 Canvas Widgets; 19.4 Coordinate Sequences; 19.5 More Widgets; 19.6 Packing Widgets; 19.7 Menus and Callables; 19.8 Binding; 19.9 Debugging; 19.10 Glossary; 19.11 Exercises; Debugging; Syntax Errors; Runtime Errors; Semantic Errors; Analysis of Algorithms; Order of Growth; Analysis of Basic Python Operations; Analysis of Search Algorithms; Hashtables; Lumpy; State Diagram; Stack Diagram; Object Diagrams; Function and Class Objects; Class Diagrams; Colophon;