New
High Performance Python
Practical Performant Programming for Humans
by Ian Ozsvald, Micha Gorelick
Pages
302
Published
2017
A Buffet of Awesome Python Features for Intermediate Developers
Master the lesser-known corners of Python so you write cleaner, more idiomatic code that your colleagues actually want to read.
Python Tricks by Dan Bader is a practical collection of bite-sized techniques that expose the hidden features and best practices most Python tutorials never cover. Each trick is self-contained, explained clearly, and backed by runnable code examples. Whether you want to write more Pythonic classes, wrangle decorators with confidence, or stop second-guessing yourself on data structures, this book gives you the working knowledge to do it right.
Most Python developers learn enough to get the job done, then hit a plateau. Their code works, but it doesn't feel quite right. They copy patterns from Stack Overflow without fully understanding why those patterns exist. They write functions that a senior Pythonista would quietly refactor the next morning.
Python Tricks is written for exactly that moment. Dan Bader spent years answering questions from intermediate Python developers on his blog and newsletter, and this book distills the most impactful answers into a single, readable volume. Each chapter focuses on one concept, shows you the problem it solves, and walks through working code you can run and modify immediately.
The tricks aren't trivia. They are the patterns that separate code that merely runs from code that is clear, robust, and easy to maintain. You'll learn how Python's object model actually works, what makes a class truly Pythonic, why some decorator patterns are traps, and how to use built-in data structures in ways that cut boilerplate in half.
The format respects your time. Every section is short enough to read on a lunch break and dense enough that you'll still be thinking about it the next morning. There are no lengthy preambles, no padded theory chapters, and no exercises that feel disconnected from real work.
If you already know the basics of Python and want to write the kind of code you'd be comfortable showing to an expert, Python Tricks is where you go next.
Covers the small but high-impact syntax habits that make Python code immediately more readable, including how idiomatic Python differs from simply correct Python.
Explores argument defaults, keyword-only arguments, and the pitfalls of mutable default values, giving you reliable patterns for defining functions that behave predictably.
Walks through how decorators work at the function-object level, how to stack them correctly, and how to use functools.wraps to preserve function metadata.
Shows how special methods like __repr__, __str__, __eq__, and __slots__ let your classes integrate naturally with Python's built-in operations and protocols.
Covers namedtuples, defaultdicts, OrderedDicts, ChainMaps, and other standard-library containers, with concrete guidance on when each one earns its place.
Teaches generator expressions, itertools patterns, and the iterator protocol so you write loops that are both memory-efficient and easy to follow.
Unpacks dictionary merging, comprehension patterns, and the correct way to iterate and mutate dicts without runtime surprises.
Brings together context managers, assertions, and exception-handling strategies that make your code safer and your intent clearer to the next reader.
You should already be comfortable with Python basics: functions, classes, loops, and standard library imports. The book is aimed at intermediate developers who want to move beyond that foundation, not complete beginners.
The vast majority of content covers core Python 3 features and idioms that have not changed. A small number of library details may reflect older minor versions, but the concepts and patterns remain accurate and applicable.
The code examples in the book are short and self-contained, designed to be typed and run directly. Check the publisher's website for any companion resources associated with your purchase.
Each section is self-contained, so you can dip in wherever a topic is relevant to something you're working on. Most readers start from the beginning and read a section or two at a time rather than in one sitting.
No. The book focuses on Python 3, which is the version you should be using for all new work.
New
Practical Performant Programming for Humans
by Ian Ozsvald, Micha Gorelick
New
A thorough reference to Python language fundamentals, from syntax and data types to classes and advanced tools
by Mark Lutz
New
A Hands-On, Project-Based Introduction to Programming in Python
by Eric Matthes
New
A Concise Desktop Reference for Python 3 β Language, Libraries, and Best Practices
by Alex Martelli, Anna Martelli Ravenscroft, Paul McGuire, Steve Holden