About This eBook
ePUB is an open, industry-standard format for eBooks. However, support of ePUB and its many features varies across reading devices and applications. Use your device or app settings to customize the presentation to your liking. Settings that you can customize often include font, font size, single or double column, landscape or portrait mode, and figures that you can click or tap to enlarge. For additional information about the settings and features on your reading device or app, visit the device manufacturers Web site.
Many titles include programming code or configuration examples. To optimize the presentation of these elements, view the eBook in single-column, landscape mode and adjust the font size to the smallest setting. In addition to presenting code and configurations in the reflowable text format, we have included images of the code that mimic the presentation found in the print book; therefore, where the reflowable format may compromise the presentation of the code listing, you will see a Click here to view code image link. Click the link to view the print-fidelity code image. To return to the previous page viewed, click the Back button on your device or app.
Praise for Effective Python
I have been recommending this book enthusiastically since the first edition appeared in 2015. This new edition, updated and expanded for Python 3, is a treasure trove of practical Python programming wisdom that can benefit programmers of all experience levels.
Wes McKinney, Creator of Python Pandas project, Director of Ursa Labs
If youre coming from another language, this is your definitive guide to taking full advantage of the unique features Python has to offer. Ive been working with Python for nearly twenty years and I still learned a bunch of useful tricks, especially around newer features introduced by Python 3. Effective Python is crammed with actionable advice, and really helps define what our community means when they talk about Pythonic code.
Simon Willison, Co-creator of Django
Ive been programming in Python for years and thought I knew it pretty well. Thanks to this treasure trove of tips and techniques, Ive discovered many ways to improve my Python code to make it faster (e.g., using bisect to search sorted lists), easier to read (e.g., enforcing keyword-only arguments), less prone to error (e.g., unpacking with starred expressions), and more Pythonic (e.g., using zip to iterate over lists in parallel). Plus, the second edition is a great way to quickly get up to speed on Python 3 features, such as the walrus operator, f-strings, and the typing module.
Pamela Fox, Creator of Khan Academy programming courses
Now that Python 3 has finally become the standard version of Python, its already gone through eight minor releases and a lot of new features have been added throughout. Brett Slatkin returns with a second edition of Effective Python with a huge new list of Python idioms and straightforward recommendations, catching up with everything thats introduced in version 3 all the way through 3.8 that well all want to use as we finally leave Python 2 behind. Early sections lay out an enormous list of tips regarding new Python 3 syntaxes and concepts like string and byte objects, f-strings, assignment expressions (and their special nickname you might not know), and catch-all unpacking of tuples. Later sections take on bigger subjects, all of which are packed with things I either didnt know or which Im always trying to teach to others, including Metaclasses and Attributes (good advice includes Prefer Class Decorators over Metaclasses and also introduces a new magic method __init_subclass__() I wasnt familiar with), Concurrency (favorite advice: Use Threads for Blocking I/O, but not Parallelism, but it also covers asyncio and coroutines correctly) and Robustness and Performance (advice given: Profile before Optimizing). Its a joy to go through each section as everything I read is terrific best practice information smartly stated, and Im considering quoting from this book in the future as it has such great advice all throughout. This is the definite winner for the if you only read one Python book this year... contest.
Mike Bayer, Creator of SQLAlchemy
This is a great book for both novice and experienced programmers. The code examples and explanations are well thought out and explained concisely and thoroughly. The second edition updates the advice for Python 3, and its fantastic! Ive been using Python for almost 20 years, and I learned something new every few pages. The advice given in this book will serve anyone well.
Titus Brown, Associate Professor at UC Davis
Once again, Brett Slatkin has managed to condense a wide range of solid practices from the community into a single volume. From exotic topics like metaclasses and concurrency to crucial basics like robustness, testing, and collaboration, the updated Effective Python makes a consensus view of whats Pythonic available to a wide audience.
Brandon Rhodes, Author of python-patterns.guide
Effective Python
Second Edition
Effective Python
90 SPECIFIC WAYS TO WRITE BETTER PYTHON
Second Edition
Brett Slatkin
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at or (800) 382-3419.
For government sales inquiries, please contact .
For questions about sales outside the U.S., please contact .
Visit us on the Web: informit.com/aw
Library of Congress Control Number: On file
Copyright 2020 Pearson Education, Inc.
All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, request forms and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearson.com/permissions/.
ISBN-13: 978-0-13-485398-7
ISBN-10: 0-13-485398-9
ScoutAutomatedPrintCode
Editor-in-Chief
Mark L. Taub