Book description
Google and YouTube use Python because it's highly adaptable, easy to maintain, and allows for rapid development. If you want to write high-quality, efficient code that's easily integrated with other languages and tools, this hands-on book will help you be productive with Python quickly -- whether you're new to programming or just new to Python. It's an easy-to-follow self-paced tutorial, based on author and Python expert Mark Lutz's popular training course.
Each chapter contains a stand-alone lesson on a key component of the language, and includes a unique Test Your Knowledge section with practical exercises and quizzes, so you can practice new skills and test your understanding as you go. You'll find lots of annotated examples and illustrations to help you get started with Python 3.0.
Learn about Python's major built-in object types, such as numbers, lists, and dictionariesCreate and process objects using Python statements, and learn Python's general syntax modelStructure and reuse code using functions, Python's basic procedural toolLearn about Python modules: packages of statements, functions, and other tools, organized into larger componentsDiscover Python's object-oriented programming tool for structuring codeLearn about the exception-handling model, and development tools for writing larger programsExplore advanced Python tools including decorators, descriptors, metaclasses, and Unicode processing
Publisher resources
Table of contents
- Dedication
- A Note Regarding Supplemental Files
- Preface
-
I. Getting Started
-
1. A Python Q&A Session
- Why Do People Use Python?
- Is Python a “Scripting Language”?
- OK, but What’s the Downside?
- Who Uses Python Today?
- What Can I Do with Python?
- How Is Python Supported?
- What Are Python’s Technical Strengths?
- How Does Python Stack Up to Language X?
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 2. How Python Runs Programs
-
3. How You Run Programs
- The Interactive Prompt
- System Command Lines and Files
- Clicking File Icons
- Module Imports and Reloads
- Using exec to Run Module Files
- The IDLE User Interface
- Other IDEs
- Other Launch Options
- Which Option Should I Use?
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part I Exercises
-
1. A Python Q&A Session
-
II. Types and Operations
- 4. Introducing Python Object Types
-
5. Numeric Types
- Numeric Type Basics
- Numbers in Action
- Other Numeric Types
- Numeric Extensions
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 6. The Dynamic Typing Interlude
- 7. Strings
-
8. Lists and Dictionaries
- Lists
- Lists in Action
- Dictionaries
- Dictionaries in Action
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 9. Tuples, Files, and Everything Else
-
III. Statements and Syntax
- 10. Introducing Python Statements
- 11. Assignments, Expressions, and Prints
- 12. if Tests and Syntax Rules
- 13. while and for Loops
- 14. Iterations and Comprehensions, Part 1
- 15. The Documentation Interlude
-
IV. Functions
- 16. Function Basics
- 17. Scopes
-
18. Arguments
- Argument-Passing Basics
- Special Argument-Matching Modes
- The min Wakeup Call!
- Generalized Set Functions
- Emulating the Python 3.0 print Function
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 19. Advanced Function Topics
-
20. Iterations and Comprehensions, Part 2
- List Comprehensions Revisited: Functional Tools
- Iterators Revisited: Generators
- 3.0 Comprehension Syntax Summary
- Timing Iteration Alternatives
- Function Gotchas
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part IV Exercises
-
V. Modules
- 21. Modules: The Big Picture
- 22. Module Coding Basics
-
23. Module Packages
- Package Import Basics
- Package Import Example
- Why Use Package Imports?
- Package Relative Imports
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
-
24. Advanced Module Topics
- Data Hiding in Modules
- Enabling Future Language Features
- Mixed Usage Modes: __name__ and __main__
- Changing the Module Search Path
- The as Extension for import and from
- Modules Are Objects: Metaprograms
- Importing Modules by Name String
- Transitive Module Reloads
- Module Design Concepts
- Module Gotchas
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part V Exercises
-
VI. Classes and OOP
- 25. OOP: The Big Picture
- 26. Class Coding Basics
-
27. A More Realistic Example
- Step 1: Making Instances
- Step 2: Adding Behavior Methods
- Step 3: Operator Overloading
- Step 4: Customizing Behavior by Subclassing
- Step 5: Customizing Constructors, Too
- Step 6: Using Introspection Tools
- Step 7 (Final): Storing Objects in a Database
- Future Directions
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 28. Class Coding Details
-
29. Operator Overloading
- The Basics
- Indexing and Slicing: __getitem__ and __setitem__
- Index Iteration: __getitem__
- Iterator Objects: __iter__ and __next__
- Membership: __contains__, __iter__, and __getitem__
- Attribute Reference: __getattr__ and __setattr__
- String Representation: __repr__ and __str__
- Right-Side and In-Place Addition: __radd__ and __iadd__
- Call Expressions: __call__
- Comparisons: __lt__, __gt__, and Others
- Boolean Tests: __bool__ and __len__
- Object Destruction: __del__
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
-
30. Designing with Classes
- Python and OOP
- OOP and Inheritance: “Is-a” Relationships
- OOP and Composition: “Has-a” Relationships
- OOP and Delegation: “Wrapper” Objects
- Pseudoprivate Class Attributes
- Methods Are Objects: Bound or Unbound
- Multiple Inheritance: “Mix-in” Classes
- Classes Are Objects: Generic Object Factories
- Other Design-Related Topics
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 31. Advanced Class Topics
-
VII. Exceptions and Tools
- 32. Exception Basics
- 33. Exception Coding Details
- 34. Exception Objects
- 35. Designing with Exceptions
-
VIII. Advanced Topics
-
36. Unicode and Byte Strings
- String Changes in 3.0
- String Basics
- Python 3.0 Strings in Action
- Coding Unicode Strings
- Using 3.0 Bytes Objects
- Using 3.0 (and 2.6) bytearray Objects
- Using Text and Binary Files
- Using Unicode Files
- Other String Tool Changes in 3.0
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 37. Managed Attributes
-
38. Decorators
- What’s a Decorator?
- The Basics
- Coding Function Decorators
- Coding Class Decorators
- Managing Functions and Classes Directly
- Example: “Private” and “Public” Attributes
- Example: Validating Function Arguments
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 39. Metaclasses
-
36. Unicode and Byte Strings
- IX. Appendixes
- Index
- About the Author
- Colophon
- Copyright
Product information
- Title: Learning Python, 4th Edition
- Author(s):
- Release date: October 2009
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9780596158064
You might also like
book
Programming Python, 4th Edition
If you've mastered Python's fundamentals, you're ready to start using it to get real work done. …
book
Learning Python
Learning Python is an introduction to the increasingly popular Python programming language. Python is an interpreted, …
book
Learning Python, 3rd Edition
Portable, powerful, and a breeze to use, Python is ideal for bothstandalone programs and scripting applications. …
book
Python in a Nutshell, 3rd Edition
Useful in many roles, from design and prototyping to testing, deployment, and maintenance, Python is consistently …