Books & Videos

Table of Contents

  1. Getting Started

    1. Chapter 1 A Python Q&A Session

      1. Why Do People Use Python?
      2. Is Python a “Scripting Language”?
      3. OK, but What’s the Downside?
      4. Who Uses Python Today?
      5. What Can I Do with Python?
      6. How Is Python Developed and Supported?
      7. What Are Python’s Technical Strengths?
      8. How Does Python Stack Up to Language X?
      9. Chapter Summary
      10. Test Your Knowledge: Quiz
      11. Test Your Knowledge: Answers
    2. Chapter 2 How Python Runs Programs

      1. Introducing the Python Interpreter
      2. Program Execution
      3. Execution Model Variations
      4. Chapter Summary
      5. Test Your Knowledge: Quiz
      6. Test Your Knowledge: Answers
    3. Chapter 3 How You Run Programs

      1. The Interactive Prompt
      2. System Command Lines and Files
      3. Unix-Style Executable Scripts: #!
      4. Clicking File Icons
      5. Module Imports and Reloads
      6. Using exec to Run Module Files
      7. The IDLE User Interface
      8. Other IDEs
      9. Other Launch Options
      10. Which Option Should I Use?
      11. Chapter Summary
      12. Test Your Knowledge: Quiz
      13. Test Your Knowledge: Answers
      14. Test Your Knowledge: Part I Exercises
  2. Types and Operations

    1. Chapter 4 Introducing Python Object Types

      1. The Python Conceptual Hierarchy
      2. Why Use Built-in Types?
      3. Python’s Core Data Types
      4. Numbers
      5. Strings
      6. Lists
      7. Dictionaries
      8. Tuples
      9. Files
      10. Other Core Types
      11. Chapter Summary
      12. Test Your Knowledge: Quiz
      13. Test Your Knowledge: Answers
    2. Chapter 5 Numeric Types

      1. Numeric Type Basics
      2. Numbers in Action
      3. Other Numeric Types
      4. Numeric Extensions
      5. Chapter Summary
      6. Test Your Knowledge: Quiz
      7. Test Your Knowledge: Answers
    3. Chapter 6 The Dynamic Typing Interlude

      1. The Case of the Missing Declaration Statements
      2. Shared References
      3. Dynamic Typing Is Everywhere
      4. Chapter Summary
      5. Test Your Knowledge: Quiz
      6. Test Your Knowledge: Answers
    4. Chapter 7 String Fundamentals

      1. This Chapter’s Scope
      2. String Basics
      3. String Literals
      4. Strings in Action
      5. String Methods
      6. String Formatting Expressions
      7. String Formatting Method Calls
      8. General Type Categories
      9. Chapter Summary
      10. Test Your Knowledge: Quiz
      11. Test Your Knowledge: Answers
    5. Chapter 8 Lists and Dictionaries

      1. Lists
      2. Lists in Action
      3. Dictionaries
      4. Dictionaries in Action
      5. Chapter Summary
      6. Test Your Knowledge: Quiz
      7. Test Your Knowledge: Answers
    6. Chapter 9 Tuples, Files, and Everything Else

      1. Tuples
      2. Files
      3. Core Types Review and Summary
      4. Built-in Type Gotchas
      5. Chapter Summary
      6. Test Your Knowledge: Quiz
      7. Test Your Knowledge: Answers
      8. Test Your Knowledge: Part II Exercises
  3. Statements and Syntax

    1. Chapter 10 Introducing Python Statements

      1. The Python Conceptual Hierarchy Revisited
      2. Python’s Statements
      3. A Tale of Two ifs
      4. A Quick Example: Interactive Loops
      5. Chapter Summary
      6. Test Your Knowledge: Quiz
      7. Test Your Knowledge: Answers
    2. Chapter 11 Assignments, Expressions, and Prints

      1. Assignment Statements
      2. Expression Statements
      3. Print Operations
      4. Chapter Summary
      5. Test Your Knowledge: Quiz
      6. Test Your Knowledge: Answers
    3. Chapter 12 if Tests and Syntax Rules

      1. if Statements
      2. Python Syntax Revisited
      3. Truth Values and Boolean Tests
      4. The if/else Ternary Expression
      5. Chapter Summary
      6. Test Your Knowledge: Quiz
      7. Test Your Knowledge: Answers
    4. Chapter 13 while and for Loops

      1. while Loops
      2. break, continue, pass, and the Loop else
      3. for Loops
      4. Loop Coding Techniques
      5. Chapter Summary
      6. Test Your Knowledge: Quiz
      7. Test Your Knowledge: Answers
    5. Chapter 14 Iterations and Comprehensions

      1. Iterations: A First Look
      2. List Comprehensions: A First Detailed Look
      3. Other Iteration Contexts
      4. New Iterables in Python 3.X
      5. Other Iteration Topics
      6. Chapter Summary
      7. Test Your Knowledge: Quiz
      8. Test Your Knowledge: Answers
    6. Chapter 15 The Documentation Interlude

      1. Python Documentation Sources
      2. Common Coding Gotchas
      3. Chapter Summary
      4. Test Your Knowledge: Quiz
      5. Test Your Knowledge: Answers
      6. Test Your Knowledge: Part III Exercises
  4. Functions and Generators

    1. Chapter 16 Function Basics

      1. Why Use Functions?
      2. Coding Functions
      3. A First Example: Definitions and Calls
      4. A Second Example: Intersecting Sequences
      5. Chapter Summary
      6. Test Your Knowledge: Quiz
      7. Test Your Knowledge: Answers
    2. Chapter 17 Scopes

      1. Python Scope Basics
      2. The global Statement
      3. Scopes and Nested Functions
      4. The nonlocal Statement in 3.X
      5. Why nonlocal? State Retention Options
      6. Chapter Summary
      7. Test Your Knowledge: Quiz
      8. Test Your Knowledge: Answers
    3. Chapter 18 Arguments

      1. Argument-Passing Basics
      2. Special Argument-Matching Modes
      3. The min Wakeup Call!
      4. Generalized Set Functions
      5. Emulating the Python 3.X print Function
      6. Chapter Summary
      7. Test Your Knowledge: Quiz
      8. Test Your Knowledge: Answers
    4. Chapter 19 Advanced Function Topics

      1. Function Design Concepts
      2. Recursive Functions
      3. Function Objects: Attributes and Annotations
      4. Anonymous Functions: lambda
      5. Functional Programming Tools
      6. Chapter Summary
      7. Test Your Knowledge: Quiz
      8. Test Your Knowledge: Answers
    5. Chapter 20 Comprehensions and Generations

      1. List Comprehensions and Functional Tools
      2. Generator Functions and Expressions
      3. Comprehension Syntax Summary
      4. Chapter Summary
      5. Test Your Knowledge: Quiz
      6. Test Your Knowledge: Answers
    6. Chapter 21 The Benchmarking Interlude

      1. Timing Iteration Alternatives
      2. Timing Iterations and Pythons with timeit
      3. Other Benchmarking Topics: pystones
      4. Function Gotchas
      5. Chapter Summary
      6. Test Your Knowledge: Quiz
      7. Test Your Knowledge: Answers
      8. Test Your Knowledge: Part IV Exercises
  5. Modules and Packages

    1. Chapter 22 Modules: The Big Picture

      1. Why Use Modules?
      2. Python Program Architecture
      3. How Imports Work
      4. Byte Code Files: __pycache__ in Python 3.2+
      5. The Module Search Path
      6. Chapter Summary
      7. Test Your Knowledge: Quiz
      8. Test Your Knowledge: Answers
    2. Chapter 23 Module Coding Basics

      1. Module Creation
      2. Module Usage
      3. Module Namespaces
      4. Reloading Modules
      5. Chapter Summary
      6. Test Your Knowledge: Quiz
      7. Test Your Knowledge: Answers
    3. Chapter 24 Module Packages

      1. Package Import Basics
      2. Package Import Example
      3. Why Use Package Imports?
      4. Package Relative Imports
      5. Python 3.3 Namespace Packages
      6. Chapter Summary
      7. Test Your Knowledge: Quiz
      8. Test Your Knowledge: Answers
    4. Chapter 25 Advanced Module Topics

      1. Module Design Concepts
      2. Data Hiding in Modules
      3. Enabling Future Language Features: __future__
      4. Mixed Usage Modes: __name__ and __main__
      5. Example: Dual Mode Code
      6. Changing the Module Search Path
      7. The as Extension for import and from
      8. Example: Modules Are Objects
      9. Importing Modules by Name String
      10. Example: Transitive Module Reloads
      11. Module Gotchas
      12. Chapter Summary
      13. Test Your Knowledge: Quiz
      14. Test Your Knowledge: Answers
      15. Test Your Knowledge: Part V Exercises
  6. Classes and OOP

    1. Chapter 26 OOP: The Big Picture

      1. Why Use Classes?
      2. OOP from 30,000 Feet
      3. Chapter Summary
      4. Test Your Knowledge: Quiz
      5. Test Your Knowledge: Answers
    2. Chapter 27 Class Coding Basics

      1. Classes Generate Multiple Instance Objects
      2. Classes Are Customized by Inheritance
      3. Classes Can Intercept Python Operators
      4. The World’s Simplest Python Class
      5. Chapter Summary
      6. Test Your Knowledge: Quiz
      7. Test Your Knowledge: Answers
    3. Chapter 28 A More Realistic Example

      1. Step 1: Making Instances
      2. Step 2: Adding Behavior Methods
      3. Step 3: Operator Overloading
      4. Step 4: Customizing Behavior by Subclassing
      5. Step 5: Customizing Constructors, Too
      6. Step 6: Using Introspection Tools
      7. Step 7 (Final): Storing Objects in a Database
      8. Future Directions
      9. Chapter Summary
      10. Test Your Knowledge: Quiz
      11. Test Your Knowledge: Answers
    4. Chapter 29 Class Coding Details

      1. The class Statement
      2. Methods
      3. Inheritance
      4. Namespaces: The Conclusion
      5. Documentation Strings Revisited
      6. Classes Versus Modules
      7. Chapter Summary
      8. Test Your Knowledge: Quiz
      9. Test Your Knowledge: Answers
    5. Chapter 30 Operator Overloading

      1. The Basics
      2. Indexing and Slicing: __getitem__ and __setitem__
      3. Index Iteration: __getitem__
      4. Iterable Objects: __iter__ and __next__
      5. Membership: __contains__, __iter__, and __getitem__
      6. Attribute Access: __getattr__ and __setattr__
      7. String Representation: __repr__ and __str__
      8. Right-Side and In-Place Uses: __radd__ and __iadd__
      9. Call Expressions: __call__
      10. Comparisons: __lt__, __gt__, and Others
      11. Boolean Tests: __bool__ and __len__
      12. Object Destruction: __del__
      13. Chapter Summary
      14. Test Your Knowledge: Quiz
      15. Test Your Knowledge: Answers
    6. Chapter 31 Designing with Classes

      1. Python and OOP
      2. OOP and Inheritance: “Is-a” Relationships
      3. OOP and Composition: “Has-a” Relationships
      4. OOP and Delegation: “Wrapper” Proxy Objects
      5. Pseudoprivate Class Attributes
      6. Methods Are Objects: Bound or Unbound
      7. Classes Are Objects: Generic Object Factories
      8. Multiple Inheritance: “Mix-in” Classes
      9. Other Design-Related Topics
      10. Chapter Summary
      11. Test Your Knowledge: Quiz
      12. Test Your Knowledge: Answers
    7. Chapter 32 Advanced Class Topics

      1. Extending Built-in Types
      2. The “New Style” Class Model
      3. New-Style Class Changes
      4. New-Style Class Extensions
      5. Static and Class Methods
      6. Decorators and Metaclasses: Part 1
      7. The super Built-in Function: For Better or Worse?
      8. Class Gotchas
      9. Chapter Summary
      10. Test Your Knowledge: Quiz
      11. Test Your Knowledge: Answers
      12. Test Your Knowledge: Part VI Exercises
  7. Exceptions and Tools

    1. Chapter 33 Exception Basics

      1. Why Use Exceptions?
      2. Exceptions: The Short Story
      3. Chapter Summary
      4. Test Your Knowledge: Quiz
      5. Test Your Knowledge: Answers
    2. Chapter 34 Exception Coding Details

      1. The try/except/else Statement
      2. The try/finally Statement
      3. Unified try/except/finally
      4. The raise Statement
      5. The assert Statement
      6. with/as Context Managers
      7. Chapter Summary
      8. Test Your Knowledge: Quiz
      9. Test Your Knowledge: Answers
    3. Chapter 35 Exception Objects

      1. Exceptions: Back to the Future
      2. Why Exception Hierarchies?
      3. Built-in Exception Classes
      4. Custom Print Displays
      5. Custom Data and Behavior
      6. Chapter Summary
      7. Test Your Knowledge: Quiz
      8. Test Your Knowledge: Answers
    4. Chapter 36 Designing with Exceptions

      1. Nesting Exception Handlers
      2. Exception Idioms
      3. Exception Design Tips and Gotchas
      4. Core Language Summary
      5. Chapter Summary
      6. Test Your Knowledge: Quiz
      7. Test Your Knowledge: Answers
      8. Test Your Knowledge: Part VII Exercises
  8. Advanced Topics

    1. Chapter 37 Unicode and Byte Strings

      1. String Changes in 3.X
      2. String Basics
      3. Coding Basic Strings
      4. Coding Unicode Strings
      5. Using 3.X bytes Objects
      6. Using 3.X/2.6+ bytearray Objects
      7. Using Text and Binary Files
      8. Using Unicode Files
      9. Other String Tool Changes in 3.X
      10. Chapter Summary
      11. Test Your Knowledge: Quiz
      12. Test Your Knowledge: Answers
    2. Chapter 38 Managed Attributes

      1. Why Manage Attributes?
      2. Properties
      3. Descriptors
      4. __getattr__ and __getattribute__
      5. Example: Attribute Validations
      6. Chapter Summary
      7. Test Your Knowledge: Quiz
    3. Chapter 39 Decorators

      1. What’s a Decorator?
      2. The Basics
      3. Coding Function Decorators
      4. Coding Class Decorators
      5. Managing Functions and Classes Directly
      6. Example: “Private” and “Public” Attributes
      7. Example: Validating Function Arguments
      8. Chapter Summary
      9. Test Your Knowledge: Quiz
      10. Test Your Knowledge: Answers
    4. Chapter 40 Metaclasses

      1. To Metaclass or Not to Metaclass
      2. The Metaclass Model
      3. Declaring Metaclasses
      4. Coding Metaclasses
      5. Inheritance and Instance
      6. Metaclass Methods
      7. Example: Adding Methods to Classes
      8. Example: Applying Decorators to Methods
      9. Chapter Summary
      10. Test Your Knowledge: Quiz
      11. Test Your Knowledge: Answers
    5. Chapter 41 All Good Things

      1. The Python Paradox
      2. Where to Go From Here
      3. Encore: Print Your Own Completion Certificate!
  9. Appendixes

    1. Appendix Installation and Configuration

      1. Installing the Python Interpreter
      2. Configuring Python
      3. For More Help
    2. Appendix The Python 3.3 Windows Launcher

      1. The Unix Legacy
      2. The Windows Legacy
      3. Introducing the New Windows Launcher
      4. A Windows Launcher Tutorial
      5. Pitfalls of the New Windows Launcher
      6. Conclusions: A Net Win for Windows
    3. Appendix Python Changes and This Book

      1. Major 2.X/3.X Differences
      2. General Remarks: 3.X Changes
      3. Fifth Edition Python Changes: 2.7, 3.2, 3.3
      4. Fourth Edition Python Changes: 2.6, 3.0, 3.1
      5. Third Edition Python Changes: 2.3, 2.4, 2.5
      6. Earlier and Later Python Changes
    4. Appendix Solutions to End-of-Part Exercises

      1. Part I, Getting Started
      2. Part II, Types and Operations
      3. Part III, Statements and Syntax
      4. Part IV, Functions and Generators
      5. Part V, Modules and Packages
      6. Part VI, Classes and OOP
      7. Part VII, Exceptions and Tools
  1. Colophon