You are reading about a previous, old version of this book. The third edition of this book (released in November, 2024) is focused exclusively on Python 3, up to and including version 3.13.
Most of the original items from the second edition have been revised and included in the third edition, but many have undergone substantial updates. For some items my advice has completely changed due best practices evolving as Python has matured.
If you’re still using an older version of Python 3 (such as 3.8 or earlier), the second edition of the book (released in November 2019) might still be useful to you.
Translations are available in 日本語, Deutsche, Polszczyzna, Hrvatski, 简体中文, 繁体中文, 한국어
An assignment expression—also known as the walrus operator—is a new syntax introduced in Python 3.8 to solve a long-standing problem with the language that can cause code duplication. Whereas normal assignment statements are written a = b
and pronounced “a equals b”, these assignments are written a := b
and pronounced “a walrus b” (because :=
looks like a pair of eyeballs and tusks).
Continue reading »
Although metaclasses allow you to customize class creation in multiple ways (see Item 48: “Validate Subclasses with __init_subclass__
” and Item 49: “Register Class Existence with __init_subclass__
”), they still fall short of handling every situation that may arise.
Continue reading »
You can immediately read the second edition of Effective Python as a DRM-free eBook, on Kindle, on Google Play, and on O’Reilly Online Learning.
memoryview
and bytearray
for Zero-Copy Interactions with bytes
Though Python isn’t able to parallelize CPU-bound computation without extra effort (see Item 64: “Consider concurrent.futures
for True Parallelism”), it is able to support high-throughput, parallel I/O in a variety of ways (see Item 53: “Use Threads for Blocking I/O, Avoid for Parallelism” and Item 60: “Achieve Highly Concurrent I/O with Coroutines” for details). That said, it’s surprisingly easy to use these I/O tools the wrong way and reach the conclusion that the language is too slow for even I/O-bound workloads.
Continue reading »
Effective Python: Second Edition is now available for preorder. Follow this link to buy your copy in advance. It will ship in mid-November (2019) once the book has finished printing and is stocked in the warehouse. Digital editions will become available when the physical book ships or sooner.