Book description
Get a comprehensive, in-depth introduction to the core Python language with this hands-on book. Based on author Mark Lutz’s popular training course, this updated fifth edition will help you quickly write efficient, high-quality code with Python. It’s an ideal way to begin, whether you’re new to programming or a professional developer versed in other languages.
Complete with quizzes, exercises, and helpful illustrations, this easy-to-follow, self-paced tutorial gets you started with both Python 2.7 and 3.3— the latest releases in the 3.X and 2.X lines—plus all other releases in common use today. You’ll also learn some advanced language features that recently have become more common in Python code.
- Explore Python’s major built-in object types such as numbers, lists, and dictionaries
- Create and process objects with Python statements, and learn Python’s general syntax model
- Use functions to avoid code redundancy and package code for reuse
- Organize statements, functions, and other tools into larger components with modules
- Dive into classes: Python’s object-oriented programming tool for structuring code
- Write large programs with Python’s exception-handling model and development tools
- Learn advanced Python tools, including decorators, descriptors, metaclasses, and Unicode processing
Publisher resources
Table of contents
- 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 Developed and 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
- Unix-Style Executable Scripts: #!
- 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
- II. Types and Operations
- 4. Introducing Python Object Types
- 5. Numeric Types
- 6. The Dynamic Typing Interlude
- 7. String Fundamentals
- 8. Lists and Dictionaries
- 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
- 15. The Documentation Interlude
- IV. Functions and Generators
- 16. Function Basics
- 17. Scopes
- 18. Arguments
- 19. Advanced Function Topics
-
20. Comprehensions and Generations
- List Comprehensions and Functional Tools
-
Generator Functions and Expressions
- Generator Functions: yield Versus return
- Generator Expressions: Iterables Meet Comprehensions
- Generator Functions Versus Generator Expressions
- Generators Are Single-Iteration Objects
- Generation in Built-in Types, Tools, and Classes
- Example: Generating Scrambled Sequences
- Don’t Abuse Generators: EIBTI
- Example: Emulating zip and map with Iteration Tools
- Comprehension Syntax Summary
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 21. The Benchmarking Interlude
- V. Modules and Packages
- 22. Modules: The Big Picture
- 23. Module Coding Basics
- 24. Module Packages
-
25. Advanced Module Topics
- Module Design Concepts
- Data Hiding in Modules
- Enabling Future Language Features: __future__
- Mixed Usage Modes: __name__ and __main__
- Example: Dual Mode Code
- Changing the Module Search Path
- The as Extension for import and from
- Example: Modules Are Objects
- Importing Modules by Name String
- Example: Transitive Module Reloads
- Module Gotchas
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part V Exercises
- VI. Classes and OOP
- 26. OOP: The Big Picture
- 27. Class Coding Basics
-
28. 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
- 29. Class Coding Details
-
30. Operator Overloading
- The Basics
- Indexing and Slicing: __getitem__ and __setitem__
- Index Iteration: __getitem__
- Iterable Objects: __iter__ and __next__
- Membership: __contains__, __iter__, and __getitem__
- Attribute Access: __getattr__ and __setattr__
- String Representation: __repr__ and __str__
- Right-Side and In-Place Uses: __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
-
31. Designing with Classes
- Python and OOP
- OOP and Inheritance: “Is-a” Relationships
- OOP and Composition: “Has-a” Relationships
- OOP and Delegation: “Wrapper” Proxy Objects
- Pseudoprivate Class Attributes
- Methods Are Objects: Bound or Unbound
- Classes Are Objects: Generic Object Factories
- Multiple Inheritance: “Mix-in” Classes
- Other Design-Related Topics
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
-
32. Advanced Class Topics
- Extending Built-in Types
- The “New Style” Class Model
- New-Style Class Changes
- New-Style Class Extensions
- Static and Class Methods
- Decorators and Metaclasses: Part 1
- The super Built-in Function: For Better or Worse?
- Class Gotchas
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- Test Your Knowledge: Part VI Exercises
- VII. Exceptions and Tools
- 33. Exception Basics
- 34. Exception Coding Details
- 35. Exception Objects
- 36. Designing with Exceptions
- VIII. Advanced Topics
- 37. Unicode and Byte Strings
- 38. Managed Attributes
- 39. Decorators
- 40. Metaclasses
- 41. All Good Things
- IX. Appendixes
- A. Installation and Configuration
- B. The Python 3.3 Windows Launcher
- C. Python Changes and This Book
- D. Solutions to End-of-Part Exercises
- Index
- About the Author
Product information
- Title: Learning Python, 5th Edition
- Author(s):
- Release date: June 2013
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781449355739
You might also like
book
Head First Python, 2nd Edition
Want to learn the Python language without slogging your way through how-to manuals? With Head First …
book
Head First Python, 3rd Edition
What will you learn from this book? Want to learn the Python language without slogging your …
book
Python Crash Course, 2nd Edition
This is the second edition of the best selling Python book in the world. Python Crash …
book
Fluent Python, 2nd Edition
Don't waste time bending Python to fit patterns you've learned in other languages. Python's simplicity lets …