Practical Programming, 2nd Edition

Book description

This book is for anyone who wants to understand computer programming. You'll learn to program in a language that' s used in millions of smartphones, tablets, and PCs. You'll code along with the book, writing programs to solve real-world problems as you learn the fundamentals of programming using Python 3. You'll learn about design, algorithms, testing, and debugging, and come away with all the tools you need to produce quality code. In this second edition, we've updated almost all the material, incorporating the lessons we've learned over the past five years of teaching Python to people new to programming.

Publisher resources

View/Submit Errata

Table of contents

  1.  Acknowledgments
  2.  Preface
    1. Online Resources
  3. 1. What’s Programming?
    1. Programs and Programming
    2. What’s a Programming Language?
    3. What’s a Bug?
    4. The Difference Between Brackets, Braces, and Parentheses
    5. Installing Python
  4. 2. Hello, Python
    1. How Does a Computer Run a Python Program?
    2. Expressions and Values: Arithmetic in Python
    3. What Is a Type?
    4. Variables and Computer Memory: Remembering Values
    5. How Python Tells You Something Went Wrong
    6. A Single Statement That Spans Multiple Lines
    7. Describing Code
    8. Making Code Readable
    9. The Object of This Chapter
    10. Exercises
  5. 3. Designing and Using Functions
    1. Functions That Python Provides
    2. Memory Addresses: How Python Keeps Track of Values
    3. Defining Our Own Functions
    4. Using Local Variables for Temporary Storage
    5. Tracing Function Calls in the Memory Model
    6. Designing New Functions: A Recipe
    7. Writing and Running a Program
    8. Omitting a Return Statement: None
    9. Dealing with Situations That Your Code Doesn’t Handle
    10. What Did You Call That?
    11. Exercises
  6. 4. Working with Text
    1. Creating Strings of Characters
    2. Using Special Characters in Strings
    3. Creating a Multiline String
    4. Printing Information
    5. Getting Information from the Keyboard
    6. Quotes About Strings in This Text
    7. Exercises
  7. 5. Making Choices
    1. A Boolean Type
    2. Choosing Which Statements to Execute
    3. Nested If Statements
    4. Remembering the Results of a Boolean Expression Evaluation
    5. You Learned About Booleans: True or False?
    6. Exercises
  8. 6. A Modular Approach to Program Organization
    1. Importing Modules
    2. Defining Your Own Modules
    3. Testing Your Code Semiautomatically
    4. Tips for Grouping Your Functions
    5. Organizing Our Thoughts
    6. Exercises
  9. 7. Using Methods
    1. Modules, Classes, and Methods
    2. Calling Methods the Object-Oriented Way
    3. Exploring String Methods
    4. What Are Those Underscores?
    5. A Methodical Review
    6. Exercises
  10. 8. Storing Collections of Data Using Lists
    1. Storing and Accessing Data in Lists
    2. Modifying Lists
    3. Operations on Lists
    4. Slicing Lists
    5. Aliasing: What’s in a Name?
    6. List Methods
    7. Working with a List of Lists
    8. A Summary List
    9. Exercises
  11. 9. Repeating Code Using Loops
    1. Processing Items in a List
    2. Processing Characters in Strings
    3. Looping Over a Range of Numbers
    4. Processing Lists Using Indices
    5. Nesting Loops in Loops
    6. Looping Until a Condition Is Reached
    7. Repetition Based on User Input
    8. Controlling Loops Using Break and Continue
    9. Repeating What You’ve Learned
    10. Exercises
  12. 10. Reading and Writing Files
    1. What Kinds of Files Are There?
    2. Opening a File
    3. Techniques for Reading Files
    4. Files over the Internet
    5. Writing Files
    6. Writing Algorithms That Use the File-Reading Techniques
    7. Multiline Records
    8. Looking Ahead
    9. Notes to File Away
    10. Exercises
  13. 11. Storing Data Using Other Collection Types
    1. Storing Data Using Sets
    2. Storing Data Using Tuples
    3. Storing Data Using Dictionaries
    4. Inverting a Dictionary
    5. Using the In Operator on Tuples, Sets, and Dictionaries
    6. Comparing Collections
    7. A Collection of New Information
    8. Exercises
  14. 12. Designing Algorithms
    1. Searching for the Smallest Values
    2. Timing the Functions
    3. At a Minimum, You Saw This
    4. Exercises
  15. 13. Searching and Sorting
    1. Searching a List
    2. Binary Search
    3. Sorting
    4. More Efficient Sorting Algorithms
    5. Mergesort: A Faster Sorting Algorithm
    6. Sorting Out What You Learned
    7. Exercises
  16. 14. Object-Oriented Programming
    1. Understanding a Problem Domain
    2. Function “Isinstance,” Class Object, and Class Book
    3. Writing a Method in Class Book
    4. Plugging into Python Syntax: More Special Methods
    5. A Little Bit of OO Theory
    6. A Case Study: Molecules, Atoms, and PDB Files
    7. Classifying What You’ve Learned
    8. Exercises
  17. 15. Testing and Debugging
    1. Why Do You Need to Test?
    2. Case Study: Testing above_freezing
    3. Case Study: Testing running_sum
    4. Choosing Test Cases
    5. Hunting Bugs
    6. Bugs We’ve Put in Your Ear
    7. Exercises
  18. 16. Creating Graphical User Interfaces
    1. Using Module Tkinter
    2. Building a Basic GUI
    3. Models, Views, and Controllers, Oh My!
    4. Customizing the Visual Style
    5. Introducing a Few More Widgets
    6. Object-Oriented GUIs
    7. Keeping the Concepts from Being a GUI Mess
    8. Exercises
  19. 17. Databases
    1. Overview
    2. Creating and Populating
    3. Retrieving Data
    4. Updating and Deleting
    5. Using NULL for Missing Data
    6. Using Joins to Combine Tables
    7. Keys and Constraints
    8. Advanced Features
    9. Some Data Based On What You Learned
    10. Exercises
  20.  Bibliography

Product information

  • Title: Practical Programming, 2nd Edition
  • Author(s): Paul Gries, Jennifer Campbell, Jason Montojo
  • Release date: September 2013
  • Publisher(s): Pragmatic Bookshelf
  • ISBN: 9781937785451