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 sixth 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 Python 3.12 and all other releases in use today. With a pragmatic focus on what you need to know, it also introduces some advanced language features that have become increasingly common in Python code.
This book helps you:
- Explore Python's built-in object types such as strings, lists, dictionaries, and files
- Create and process objects with Python statements, and learn Python's syntax model
- Use functions and functional programming to avoid redundancy and maximize reuse
- Organize code into larger components with modules and packages
- Code robust programs with Python's exception handling and development tools
- Apply object-oriented programming and classes to make code customizable
- Survey advanced Python tools including decorators, descriptors, and metaclasses
- Write idiomatic Python code that runs portably across a wide variety of platforms
Publisher resources
Table of contents
- Preface
- I. Getting Started
- 1. A Python Q&A Session
- 2. How Python Runs Programs
- 3. How You Run Programs
- II. Objects and Operations
- 4. Introducing Python Objects
- 5. Numbers and Expressions
- 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 and match Selections
- 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. Function Odds and Ends
- 20. Comprehensions and Generations
- 21. The Benchmarking Interlude
- V. Modules and Packages
- 22. Modules: The Big Picture
- 23. Module Coding Basics
- 24. Module Packages
-
25. Module Odds and Ends
- Module Design Concepts
- Data Hiding in Modules
- Enabling Language Changes: __future__
- Dual-Usage Modes: __name__ and __main__
- The as Extension for import and from
- Module Introspection
- Importing Modules by Name String
- 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 Ops: __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: “Like-a” Relationships
- Pseudoprivate Class Attributes
- Method Objects: Bound or Not
- Classes Are Objects: Generic Object Factories
- Multiple Inheritance and the MRO
- Other Design-Related Topics
- Chapter Summary
- Test Your Knowledge: Quiz
- Test Your Knowledge: Answers
- 32. Class Odds and Ends
- VII. Exceptions
- 33. Exception Basics
- 34. Exception Coding Details
- 35. Exception Objects
- 36. Exception Odds and Ends
- VIII. Advanced Topics
- 37. Unicode and Byte Strings
- 38. Managed Attributes
- 39. Decorators
- 40. Metaclasses and Inheritance
- 41. All Good Things
- IX. Appendixes
- A. Platform Usage Tips
- B. Solutions to End-of-Part Exercises
- About the Author
Product information
- Title: Learning Python, 6th Edition
- Author(s):
- Release date: May 2025
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781098171308
You might also like
book
Effective Python: 125 Specific Ways to Write Better Python, 3rd Edition
Master the art of Python programming with 125 actionable best practices to write more efficient, readable, …
book
Learning Python, 5th Edition
Get a comprehensive, in-depth introduction to the core Python language with this hands-on book. Based on …
book
Object-Oriented Python
Object-Oriented Python (OOP) is a paradigm that combines data and code into cohesive units, allowing you …
book
Python Workout
The only way to master a skill is to practice. In Python Workout, author Reuven M. …