Shop now Learn more Shop now Shop Clothing clo_fly_aw15_NA_shoes Shop All Shop All Amazon Fashion Cloud Drive Photos Shop now Learn More Shop now Shop Fire HD 6 Shop Kindle Paperwhite Shop now Shop Now Shop now

Have one to sell? Sell yours here
Tell the Publisher!
I’d like to read this book on Kindle

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Learning Python [Hardcover]

3.8 out of 5 stars  See all reviews (20 customer reviews)

Currently unavailable.
We don't know when or if this item will be back in stock.


‹  Return to Product Overview

Table of Contents

Dedication; Preface; About This Fourth Edition; About The Third Edition; About This Book; Book Updates; About the Programs in This Book; Using Code Examples; Font Conventions; Safari® Books Online; How to Contact Us; Acknowledgments; Getting Started; Chapter 1: A Python Q&A Session; 1.1 Why Do People Use Python?; 1.2 Is Python a “Scripting Language”?; 1.3 OK, but What’s the Downside?; 1.4 Who Uses Python Today?; 1.5 What Can I Do with Python?; 1.6 How Is Python Supported?; 1.7 What Are Python’s Technical Strengths?; 1.8 How Does Python Stack Up to Language X?; 1.9 Chapter Summary; 1.10 Test Your Knowledge: Quiz; 1.11 Test Your Knowledge: Answers; Chapter 2: How Python Runs Programs; 2.1 Introducing the Python Interpreter; 2.2 Program Execution; 2.3 Execution Model Variations; 2.4 Chapter Summary; 2.5 Test Your Knowledge: Quiz; 2.6 Test Your Knowledge: Answers; Chapter 3: How You Run Programs; 3.1 The Interactive Prompt; 3.2 System Command Lines and Files; 3.3 Clicking File Icons; 3.4 Module Imports and Reloads; 3.5 Using exec to Run Module Files; 3.6 The IDLE User Interface; 3.7 Other IDEs; 3.8 Other Launch Options; 3.9 Which Option Should I Use?; 3.10 Chapter Summary; 3.11 Test Your Knowledge: Quiz; 3.12 Test Your Knowledge: Answers; 3.13 Test Your Knowledge: Part I Exercises; Types and Operations; Chapter 4: Introducing Python Object Types; 4.1 Why Use Built-in Types?; 4.2 Numbers; 4.3 Strings; 4.4 Lists; 4.5 Dictionaries; 4.6 Tuples; 4.7 Files; 4.8 Other Core Types; 4.9 Chapter Summary; 4.10 Test Your Knowledge: Quiz; 4.11 Test Your Knowledge: Answers; Chapter 5: Numeric Types; 5.1 Numeric Type Basics; 5.2 Numbers in Action; 5.3 Other Numeric Types; 5.4 Numeric Extensions; 5.5 Chapter Summary; 5.6 Test Your Knowledge: Quiz; 5.7 Test Your Knowledge: Answers; Chapter 6: The Dynamic Typing Interlude; 6.1 The Case of the Missing Declaration Statements; 6.2 Shared References; 6.3 Dynamic Typing Is Everywhere; 6.4 Chapter Summary; 6.5 Test Your Knowledge: Quiz; 6.6 Test Your Knowledge: Answers; Chapter 7: Strings; 7.1 String Literals; 7.2 Strings in Action; 7.3 String Methods; 7.4 String Formatting Expressions; 7.5 String Formatting Method Calls; 7.6 General Type Categories; 7.7 Chapter Summary; 7.8 Test Your Knowledge: Quiz; 7.9 Test Your Knowledge: Answers; Chapter 8: Lists and Dictionaries; 8.1 Lists; 8.2 Lists in Action; 8.3 Dictionaries; 8.4 Dictionaries in Action; 8.5 Chapter Summary; 8.6 Test Your Knowledge: Quiz; 8.7 Test Your Knowledge: Answers; Chapter 9: Tuples, Files, and Everything Else; 9.1 Tuples; 9.2 Files; 9.3 Type Categories Revisited; 9.4 Object Flexibility; 9.5 References Versus Copies; 9.6 Comparisons, Equality, and Truth; 9.7 Python’s Type Hierarchies; 9.8 Other Types in Python; 9.9 Built-in Type Gotchas; 9.10 Chapter Summary; 9.11 Test Your Knowledge: Quiz; 9.12 Test Your Knowledge: Answers; 9.13 Test Your Knowledge: Part II Exercises; Statements and Syntax; Chapter 10: Introducing Python Statements; 10.1 Python Program Structure Revisited; 10.2 A Tale of Two ifs; 10.3 A Quick Example: Interactive Loops; 10.4 Chapter Summary; 10.5 Test Your Knowledge: Quiz; 10.6 Test Your Knowledge: Answers; Chapter 11: Assignments, Expressions, and Prints; 11.1 Assignment Statements; 11.2 Expression Statements; 11.3 Print Operations; 11.4 Chapter Summary; 11.5 Test Your Knowledge: Quiz; 11.6 Test Your Knowledge: Answers; Chapter 12: if Tests and Syntax Rules; 12.1 if Statements; 12.2 Python Syntax Rules; 12.3 Truth Tests; 12.4 The if/else Ternary Expression; 12.5 Chapter Summary; 12.6 Test Your Knowledge: Quiz; 12.7 Test Your Knowledge: Answers; Chapter 13: while and for Loops; 13.1 while Loops; 13.2 break, continue, pass, and the Loop else; 13.3 for Loops; 13.4 Loop Coding Techniques; 13.5 Chapter Summary; 13.6 Test Your Knowledge: Quiz; 13.7 Test Your Knowledge: Answers; Chapter 14: Iterations and Comprehensions, Part 1; 14.1 Iterators: A First Look; 14.2 List Comprehensions: A First Look; 14.3 Other Iteration Contexts; 14.4 New Iterables in Python 3.0; 14.5 Other Iterator Topics; 14.6 Chapter Summary; 14.7 Test Your Knowledge: Quiz; 14.8 Test Your Knowledge: Answers; Chapter 15: The Documentation Interlude; 15.1 Python Documentation Sources; 15.2 Common Coding Gotchas; 15.3 Chapter Summary; 15.4 Test Your Knowledge: Quiz; 15.5 Test Your Knowledge: Answers; 15.6 Test Your Knowledge: Part III Exercises; Functions; Chapter 16: Function Basics; 16.1 Why Use Functions?; 16.2 Coding Functions; 16.3 A First Example: Definitions and Calls; 16.4 A Second Example: Intersecting Sequences; 16.5 Chapter Summary; 16.6 Test Your Knowledge: Quiz; 16.7 Test Your Knowledge: Answers; Chapter 17: Scopes; 17.1 Python Scope Basics; 17.2 The global Statement; 17.3 Scopes and Nested Functions; 17.4 The nonlocal Statement; 17.5 Chapter Summary; 17.6 Test Your Knowledge: Quiz; 17.7 Test Your Knowledge: Answers; Chapter 18: Arguments; 18.1 Argument-Passing Basics; 18.2 Special Argument-Matching Modes; 18.3 The min Wakeup Call!; 18.4 Generalized Set Functions; 18.5 Emulating the Python 3.0 print Function; 18.6 Chapter Summary; 18.7 Test Your Knowledge: Quiz; 18.8 Test Your Knowledge: Answers; Chapter 19: Advanced Function Topics; 19.1 Function Design Concepts; 19.2 Recursive Functions; 19.3 Function Objects: Attributes and Annotations; 19.4 Anonymous Functions: lambda; 19.5 Mapping Functions over Sequences: map; 19.6 Functional Programming Tools: filter and reduce; 19.7 Chapter Summary; 19.8 Test Your Knowledge: Quiz; 19.9 Test Your Knowledge: Answers; Chapter 20: Iterations and Comprehensions, Part 2; 20.1 List Comprehensions Revisited: Functional Tools; 20.2 Iterators Revisited: Generators; 20.3 3.0 Comprehension Syntax Summary; 20.4 Timing Iteration Alternatives; 20.5 Function Gotchas; 20.6 Chapter Summary; 20.7 Test Your Knowledge: Quiz; 20.8 Test Your Knowledge: Answers; 20.9 Test Your Knowledge: Part IV Exercises; Modules; Chapter 21: Modules: The Big Picture; 21.1 Why Use Modules?; 21.2 Python Program Architecture; 21.3 How Imports Work; 21.4 The Module Search Path; 21.5 Chapter Summary; 21.6 Test Your Knowledge: Quiz; 21.7 Test Your Knowledge: Answers; Chapter 22: Module Coding Basics; 22.1 Module Creation; 22.2 Module Usage; 22.3 Module Namespaces; 22.4 Reloading Modules; 22.5 Chapter Summary; 22.6 Test Your Knowledge: Quiz; 22.7 Test Your Knowledge: Answers; Chapter 23: Module Packages; 23.1 Package Import Basics; 23.2 Package Import Example; 23.3 Why Use Package Imports?; 23.4 Package Relative Imports; 23.5 Chapter Summary; 23.6 Test Your Knowledge: Quiz; 23.7 Test Your Knowledge: Answers; Chapter 24: Advanced Module Topics; 24.1 Data Hiding in Modules; 24.2 Enabling Future Language Features; 24.3 Mixed Usage Modes: __name__ and __main__; 24.4 Changing the Module Search Path; 24.5 The as Extension for import and from; 24.6 Modules Are Objects: Metaprograms; 24.7 Importing Modules by Name String; 24.8 Transitive Module Reloads; 24.9 Module Design Concepts; 24.10 Module Gotchas; 24.11 Chapter Summary; 24.12 Test Your Knowledge: Quiz; 24.13 Test Your Knowledge: Answers; 24.14 Test Your Knowledge: Part V Exercises; Classes and OOP; Chapter 25: OOP: The Big Picture; 25.1 Why Use Classes?; 25.2 OOP from 30,000 Feet; 25.3 Chapter Summary; 25.4 Test Your Knowledge: Quiz; 25.5 Test Your Knowledge: Answers; Chapter 26: Class Coding Basics; 26.1 Classes Generate Multiple Instance Objects; 26.2 Classes Are Customized by Inheritance; 26.3 Classes Can Intercept Python Operators; 26.4 The World’s Simplest Python Class; 26.5 Chapter Summary; 26.6 Test Your Knowledge: Quiz; 26.7 Test Your Knowledge: Answers; Chapter 27: A More Realistic Example; 27.1 Step 1: Making Instances; 27.2 Step 2: Adding Behavior Methods; 27.3 Step 3: Operator Overloading; 27.4 Step 4: Customizing Behavior by Subclassing; 27.5 Step 5: Customizing Constructors, Too; 27.6 Step 6: Using Introspection Tools; 27.7 Step 7 (Final): Storing Objects in a Database; 27.8 Future Directions; 27.9 Chapter Summary; 27.10 Test Your Knowledge: Quiz; 27.11 Test Your Knowledge: Answers; Chapter 28: Class Coding Details; 28.1 The class Statement; 28.2 Methods; 28.3 Inheritance; 28.4 Namespaces: The Whole Story; 28.5 Documentation Strings Revisited; 28.6 Classes Versus Modules; 28.7 Chapter Summary; 28.8 Test Your Knowledge: Quiz; 28.9 Test Your Knowledge: Answers; Chapter 29: Operator Overloading; 29.1 The Basics; 29.2 Indexing and Slicing: __getitem__ and __setitem__; 29.3 Index Iteration: __getitem__; 29.4 Iterator Objects: __iter__ and __next__; 29.5 Membership: __contains__, __iter__, and __getitem__; 29.6 Attribute Reference: __getattr__ and __setattr__; 29.7 String Representation: __repr__ and __str__; 29.8 Right-Side and In-Place Addition: __radd__ and __iadd__; 29.9 Call Expressions: __call__; 29.10 Comparisons: __lt__, __gt__, and Others; 29.11 Boolean Tests: __bool__ and __len__; 29.12 Object Destruction: __del__; 29.13 Chapter Summary; 29.14 Test Your Knowledge: Quiz; 29.15 Test Your Knowledge: Answers; Chapter 30: Designing with Classes; 30.1 Python and OOP; 30.2 OOP and Inheritance: “Is-a” Relationships; 30.3 OOP and Composition: “Has-a” Relationships; 30.4 OOP and Delegation: “Wrapper” Objects; 30.5 Pseudoprivate Class Attributes; 30.6 Methods Are Objects: Bound or Unbound; 30.7 Multiple Inheritance: “Mix-in” Classes; 30.8 Classes Are Objects: Generic Object Factories; 30.9 Other Design-Related Topics; 30.10 Chapter Summary; 30.11 Test Your Knowledge: Quiz; 30.12 Test Your Knowledge: Answers; Chapter 31: Advanced Class Topics; 31.1 Extending Built-in Types; 31.2 The “New-Style” Class Model; 31.3 New-Style Class Changes; 31.4 New-Style Class Extensions; 31.5 Static and Class Methods; 31.6 Decorators and Metaclasses: Part 1; 31.7 Class Gotchas; 31.8 Chapter Summary; 31.9 Test Your Knowledge: Quiz; 31.10 Test Your Knowledge: Answers; 31.11 Test Your Knowledge: Part VI Exercises; Exceptions and Tools; Chapter 32: Exception Basics; 32.1 Why Use Exceptions?; 32.2 Exceptions: The Short Story; 32.3 Chapter Summary; 32.4 Test Your Knowledge: Quiz; 32.5 Test Your Knowledge: Answers; Chapter 33: Exception Coding Details; 33.1 The try/except/else Statement; 33.2 The try/finally Statement; 33.3 Unified try/except/finally; 33.4 The raise Statement; 33.5 The assert Statement; 33.6 with/as Context Managers; 33.7 Chapter Summary; 33.8 Test Your Knowledge: Quiz; 33.9 Test Your Knowledge: Answers; Chapter 34: Exception Objects; 34.1 Exceptions: Back to the Future; 34.2 Why Exception Hierarchies?; 34.3 Built-in Exception Classes; 34.4 Custom Print Displays; 34.5 Custom Data and Behavior; 34.6 Chapter Summary; 34.7 Test Your Knowledge: Quiz; 34.8 Test Your Knowledge: Answers; Chapter 35: Designing with Exceptions; 35.1 Nesting Exception Handlers; 35.2 Exception Idioms; 35.3 Exception Design Tips and Gotchas; 35.4 Core Language Summary; 35.5 Chapter Summary; 35.6 Test Your Knowledge: Quiz; 35.7 Test Your Knowledge: Answers; 35.8 Test Your Knowledge: Part VII Exercises; Advanced Topics; Chapter 36: Unicode and Byte Strings; 36.1 String Changes in 3.0; 36.2 String Basics; 36.3 Python 3.0 Strings in Action; 36.4 Coding Unicode Strings; 36.5 Using 3.0 Bytes Objects; 36.6 Using 3.0 (and 2.6) bytearray Objects; 36.7 Using Text and Binary Files; 36.8 Using Unicode Files; 36.9 Other String Tool Changes in 3.0; 36.10 Chapter Summary; 36.11 Test Your Knowledge: Quiz; 36.12 Test Your Knowledge: Answers; Chapter 37: Managed Attributes; 37.1 Why Manage Attributes?; 37.2 Properties; 37.3 Descriptors; 37.4 __getattr__ and __getattribute__; 37.5 Example: Attribute Validations; 37.6 Chapter Summary; 37.7 Test Your Knowledge: Quiz; Chapter 38: Decorators; 38.1 What’s a Decorator?; 38.2 The Basics; 38.3 Coding Function Decorators; 38.4 Coding Class Decorators; 38.5 Managing Functions and Classes Directly; 38.6 Example: “Private” and “Public” Attributes; 38.7 Example: Validating Function Arguments; 38.8 Chapter Summary; 38.9 Test Your Knowledge: Quiz; 38.10 Test Your Knowledge: Answers; Chapter 39: Metaclasses; 39.1 To Metaclass or Not to Metaclass; 39.2 The Metaclass Model; 39.3 Declaring Metaclasses; 39.4 Coding Metaclasses; 39.5 Example: Adding Methods to Classes; 39.6 Example: Applying Decorators to Methods; 39.7 Chapter Summary; 39.8 Test Your Knowledge: Quiz; 39.9 Test Your Knowledge: Answers; Appendixes; Installation and Configuration; Installing the Python Interpreter; Configuring Python; For More Help; Solutions to End-of-Part Exercises; Part I, Getting Started; Part II, Types and Operations; Part III, Statements and Syntax; Part IV, Functions; Part V, Modules; Part VI, Classes and OOP; Part VII, Exceptions and Tools; Colophon;|

  • Dedication
  • Preface
  • Getting Started
    • Chapter 1: A Python Q&A Session
    • Chapter 2: How Python Runs Programs
    • Chapter 3: How You Run Programs
  • Types and Operations
    • Chapter 4: Introducing Python Object Types
    • Chapter 5: Numeric Types
    • Chapter 6: The Dynamic Typing Interlude
    • Chapter 7: Strings
    • Chapter 8: Lists and Dictionaries
    • Chapter 9: Tuples, Files, and Everything Else
  • Statements and Syntax
    • Chapter 10: Introducing Python Statements
    • Chapter 11: Assignments, Expressions, and Prints
    • Chapter 12: if Tests and Syntax Rules
    • Chapter 13: while and for Loops
    • Chapter 14: Iterations and Comprehensions, Part 1
    • Chapter 15: The Documentation Interlude
  • Functions
    • Chapter 16: Function Basics
    • Chapter 17: Scopes
    • Chapter 18: Arguments
    • Chapter 19: Advanced Function Topics
    • Chapter 20: Iterations and Comprehensions, Part 2
  • Modules
    • Chapter 21: Modules: The Big Picture
    • Chapter 22: Module Coding Basics
    • Chapter 23: Module Packages
    • Chapter 24: Advanced Module Topics
  • Classes and OOP
    • Chapter 25: OOP: The Big Picture
    • Chapter 26: Class Coding Basics
    • Chapter 27: A More Realistic Example
    • Chapter 28: Class Coding Details
    • Chapter 29: Operator Overloading
    • Chapter 30: Designing with Classes
    • Chapter 31: Advanced Class Topics
  • Exceptions and Tools
    • Chapter 32: Exception Basics
    • Chapter 33: Exception Coding Details
    • Chapter 34: Exception Objects
    • Chapter 35: Designing with Exceptions
  • Advanced Topics
    • Chapter 36: Unicode and Byte Strings
    • Chapter 37: Managed Attributes
    • Chapter 38: Decorators
    • Chapter 39: Metaclasses
  • Appendixes
    • Installation and Configuration
    • Solutions to End-of-Part Exercises
  • Colophon

‹  Return to Product Overview