You are previewing Practical Programming, 2nd Edition.
O'Reilly logo
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.

Table of Contents

  1. Practical Programming, 2nd Edition
  2. For the Best Reading Experience...
  3. Table of Contents
  4. What Readers Are Saying About Practical Programming, Second Edition
  5. Acknowledgments
  6. Preface
    1. Our Approach
    2. Further Reading
    3. What You’ll See
    4. Online Resources
  7. Chapter 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
  8. Chapter 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
  9. Chapter 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
  10. Chapter 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
  11. Chapter 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
  12. Chapter 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
  13. Chapter 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
  14. Chapter 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
  15. Chapter 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
  16. Chapter 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
  17. Chapter 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
  18. Chapter 12: Designing Algorithms
    1. Searching for the Smallest Values
    2. Timing the Functions
    3. At a Minimum, You Saw This
    4. Exercises
  19. Chapter 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
  20. Chapter 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
  21. Chapter 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
  22. Chapter 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
  23. Chapter 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
  24. Bibliography
    1. You May Be Interested In…