虾吃什么| 什么叫西米| 脚抽筋是什么原因| 画五行属什么| 女人为什么会患得患失| 妈妈是什么| 尿路感染不能吃什么东西| 前白蛋白是什么意思| 治疗勃起困难有什么药| 侍妾是什么意思| 牛油果坏了是什么样| 郑州有什么大学| 梦见搬家是什么预兆| 蛇头疮用什么治疗最快| 冰释前嫌的释是什么意思| 尿隐血是什么意思| 海肠是什么动物| 被口是什么感觉| 达英35是什么| 做空是什么意思啊| 包皮开裂是什么原因| 有伤口吃什么消炎药| 挂靠是什么意思| 舌苔发黑是什么病的前兆| 晚上睡觉盗汗是什么原因| 阴虚吃什么药效果最好| 打夜针是什么意思| 老是掉头发什么原因| 翊字是什么意思| 乖巧是什么意思| 留置针是什么| 1988年出生是什么命| hpv长什么样| 月亮是什么意思| 2017是什么年| ua是什么单位| 甲状腺是什么原因引起的| 胃溃疡什么症状| 检查过敏源挂什么科| 口腔溃疡一直不好是什么原因| 知府相当于现在什么官| 强痛定又叫什么| 代偿期和失代偿期是什么意思| 什么蛋不能吃| 眉头有痣代表什么| 痰湿体质吃什么食物好| 下降头是什么意思| 身份证照片穿什么颜色衣服| 女人物质是什么意思| 春天像什么的比喻句| 主母是什么意思| 嗓子有点疼吃什么药| fbi是什么| 子宫脱落是什么原因引起的| 血小板比积偏高是什么意思| 吃核桃有什么好处| 梦见一个人代表什么| 尿黄尿味大难闻是什么原因| 胃不舒服吃什么好| 哇咔咔是什么意思| 利血平是什么药| 肾功能不好有什么症状| 马马虎虎指什么生肖| 士官是什么级别| 祛是什么意思| 妇科炎症是什么原因引起的| 越五行属性是什么| 毛孔大什么原因形成的| 心脏不舒服吃什么药最好| 羊水指数和羊水深度有什么区别| 一厢情愿指什么生肖| 下边瘙痒是什么原因| 苏打水为什么是甜的| 寿者相什么意思| 综合能力测试考什么| 右肺小结节是什么意思| 肩膀的肌肉叫什么| 老年人适合吃什么| 复印病历需要什么证件| 红红的苹果像什么句子| 痔疮为什么不建议手术| 打一个喷嚏代表什么意思| 血用什么能洗掉| 淋巴癌是什么| 副部长是什么级别| 什么动物捉害虫| 吴亦凡为什么叫牛| 梦见好多狗是什么预兆| 脸长的人适合什么发型| 宫颈息肉有什么危害| 蓝桉什么意思| 水化是什么意思| 包皮看什么科| sam是什么意思| 肠易激综合征是什么病| 放我鸽子是什么意思| 相濡以沫是什么意思| 亚甲蓝注射起什么作用| 硫酸羟氯喹片治什么病| ca199偏高是什么原因| 肝弥漫性病变是什么意思| 什么是基础病| gccg是什么牌子| dpa是什么意思| 宝宝乳糖不耐受喝什么奶粉比较好| 乾隆为什么长寿| 吃什么会食物中毒| 飞机不能带什么| 梦见车丢了是什么征兆| 瞳孔放大意味着什么| 亚蒂息肉是什么意思| 她将是你的新娘是什么歌| 福州五行属什么| 放屁多吃什么药好| 突然停经是什么原因| 2.4什么星座| 职业病是指什么| 凉烟都有什么牌子| 孕妇梦见别人怀孕是什么意思| gv是什么| 命格是什么意思| moncler是什么品牌| 银耳和雪耳有什么区别| 国企属于什么编制| pac是什么| 什么叫阳虚| 口臭吃什么好| 四离日是什么意思| 肾结石少吃什么食物| 铜钱草能治什么病| 什么时候测试怀孕最准确的| 尿路感染检查什么项目| 什么样的教诲| 河南人喜欢吃什么| 什么玉最好有灵性养人| 白细胞减少有什么症状| 眼角发痒是什么原因| 暂停服务是什么意思| 江西有什么好玩的地方| 小号避孕套是什么尺寸| 吐黄痰是什么原因| 什么饼不能吃脑筋急转弯| 青蛙怕什么| 脉压差小是什么原因| 企业背书是什么意思| 什么不什么身| 不能吃油腻的是什么病| 世界上最大的海洋是什么| 时柱比肩是什么意思| 黄色裤子配什么上衣好看| 借你吉言是什么意思| 毕业典礼送什么花| 流氓兔什么意思| 果脯是什么| 后壁和前壁有什么区别| 牙齿遇冷热都痛是什么原因| 承情是什么意思| 惊喜的英文是什么| 合龙是什么意思| 喝中药尿黄是什么原因| bbc是什么意思| 女人左眼皮跳是什么预兆| 为什么要拔掉智齿| 阴茎不硬是什么原因| 血热吃什么药可以凉血| 斗志昂扬是什么意思| 三亚在海南的什么位置| 相濡以沫什么意思| 来大姨妈不能吃什么水果| 臆想症是什么| 什么胃病需要做手术| superman什么意思| 老虔婆是什么意思| 什么叫射频消融| 狼吃什么| 耳朵流血是什么原因| 双环征是什么意思| 拐子是什么鱼| 舌苔有裂纹是什么原因| 窦性心律过缓什么意思| 孕妇做唐筛是检查什么| 女人每天喝什么最养颜| prbpm是什么意思| 亚撒西什么意思| 预防更年期提前应该吃点什么药| tg是什么| 工作单位是什么意思| 胶体金法是什么意思| 喉咙有异物感看什么科| 手心红是什么原因| 为什么妇科病要肛门塞药| 布谷鸟长什么样| 甘露醇是治什么的| 所不欲勿施于人是什么意思| 女性憋不住尿是什么原因| 十三幺是什么意思| 肌酐高是什么原因造成的| 横纹肌溶解什么意思| 汗蒸有什么好处和功效| 一级医院是什么医院| 低血压吃什么食物好| 子宫出血什么原因| 天外有天人外有人是什么意思| 女人脱发是什么原因| 山楂搭配什么泡水喝好| 希特勒为什么恨犹太人| 甲状腺结节什么症状| 原图是什么意思| 什么是气胸有什么症状| 籍贯写什么| 可定是什么药| 吃什么能去湿气最好| 风湿吃什么药好| fw什么意思| 专技十三级是什么意思| 腹泻可以吃什么| ppl什么意思| camp医学上是什么意思| super star是什么意思| 汗水多吃什么药| 痛风吃什么药治疗最有效| ida是什么意思| 瓞是什么意思| 元气大伤什么意思| 黄山四绝是什么| 井代表什么生肖| 白细胞计数偏低是什么原因| 腮帮子长痘痘是什么原因| 孕妇感冒可以吃什么感冒药| 娇羞是什么意思| 眩晕症是什么引起的| 生日派对是什么意思| exo什么时候出道的| 虐心是什么意思| 什么是痔疮早期图片| 御守是什么| 搭桥和支架有什么区别| 屁多又臭是什么原因| 小孩智力发育迟缓挂什么科| 追龙什么意思| 1963年属兔的是什么命| 总胆红素高是什么病| 囗腔溃疡吃什么维生素| 非常的近义词是什么| 鼻子出汗多是什么原因| seiko是什么牌子| 什么样的河流| 此地无银三百两是什么意思| 屎壳郎为什么要推粪球| 大黄米是什么米| 打嗝是什么意思| 人为什么会做梦| 吃炒黑豆有什么好处和坏处| 三个目念什么| 语素是什么| pe是什么意思| 心魔是什么意思| 肾阳虚是什么意思| 什么人容易得类风湿| 一什么地| 煜什么意思| 脂肪肝什么症状| 王妃是什么意思| hcmv是什么病毒| 百度

Home > Store

Effective Python: 125 Specific Ways to Write Better Python, 3rd Edition

Register your product to gain access to bonus material or receive a coupon.

林依晨时隔五年再演古装剧 搭戏古装小生引粉丝期待

Best Value Purchase

Book + eBook Bundle

  • Your Price: $75.59
  • List Price: $125.98
  • Includes EPUB and PDF
  • About eBook Formats
  • 百度 春天作为一个调养身体的好季节,而春季想要养生则可以从饮食开始入手,那么春季养生保健喝什么汤好呢?春季喝养生汤的好处春季养生汤的好处多多。

    This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Acrobat® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

More Purchase Options

Book

  • Your Price: $55.99
  • List Price: $69.99
  • Usually ships in 24 hours.

eBook

  • Your Price: $44.79
  • List Price: $55.99
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Acrobat® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

Description

  • Copyright 2025
  • Dimensions: 7" x 9-1/8"
  • Pages: 672
  • Edition: 3rd
  • Book
  • ISBN-10: 0-13-817218-8
  • ISBN-13: 978-0-13-817218-3

Master the art of Python programming with 125 actionable best practices to write more efficient, readable, and maintainable code.

Python is a versatile and powerful language, but leveraging its full potential requires more than just knowing the syntax. Effective Python: 125 Specific Ways to Write Better Python, 3rd Edition is your comprehensive guide to mastering Python's unique strengths and avoiding its hidden pitfalls. This updated edition builds on the acclaimed second edition, expanding from 90 to 125 best practices that are essential for writing high-quality Python code.

Drawing on years of experience at Google, Brett Slatkin offers clear, concise, and practical advice for both new and experienced Python developers. Each item in the book provides insight into the "Pythonic" way of programming, helping you understand how to write code that is not only effective but also elegant and maintainable. Whether you're building web applications, analyzing data, writing automation scripts, or training AI models, this book will equip you with the skills to make a significant impact using Python.

Key Features of the 3rd Edition:

  • Expanded Content: Now with 125 actionable guidelines, including 35 entirely new items.
  • Updated Best Practices: Reflects the latest features in Python releases up to version 3.13.
  • New Chapters: Additional chapters on how to build robust programs that achieve high performance.
  • Advanced Topics: In-depth coverage of creating C-extension modules and interfacing with native shared libraries.
  • Practical Examples: Realistic code examples that illustrate each best practice.

Sample Content

Online Sample Chapter

Functions

Sample Pages

Download the sample pages (includes Chapter 5)

Table of Contents

Preface     xvii

Acknowledgments     xxiii

About the Author     xxv

Chapter 1: Pythonic Thinking     1

     Item 1: Know Which Version of Python Youre Using     1

     Item 2: Follow the PEP 8 Style Guide     3

     Item 3: Never Expect Python to Detect Errors at Compile Time     6

     Item 4: Write Helper Functions Instead of Complex Expressions     8

     Item 5: Prefer Multiple-Assignment Unpacking Over Indexing     11

     Item 6: Always Surround Single-Element Tuples with Parentheses     16

     Item 7: Consider Conditional Expressions for Simple Inline Logic     19

     Item 8: Prevent Repetition with Assignment Expressions     24

     Item 9: Consider match for Destructuring in Flow Control; Avoid When if Statements Are Sufficient     30

Chapter 2: Strings and Slicing     41

     Item 10: Know the Differences Between bytes and str     41

     Item 11: Prefer Interpolated F-Strings over C-Style Format Strings and str.format     47

     Item 12: Understand the Difference Between  repr and str when Printing Objects     58

     Item 13: Prefer Explicit String Concatenation over Implicit, Especially in Lists     62

     Item 14: Know How to Slice Sequences     67

     Item 15: Avoid Striding and Slicing in a Single Expression     70

     Item 16: Prefer Catch-All Unpacking Over Slicing     72

Chapter 3: Loops and Iterators     77

     Item 17: Prefer enumerate over range     77

     Item 18: Use zip to Process Iterators in Parallel     79

     Item 19: Avoid else Blocks After for and while Loops     82

     Item 20: Never Use for Loop Variables After the Loop Ends     85

     Item 21: Be Defensive when Iterating over Arguments     87

     Item 22: Never Modify Containers While Iterating over Them; Use Copies or Caches Instead     92

     Item 23: Pass Iterators to any and all for Efficient Short-Circuiting Logic     98

     Item 24: Consider itertools for Working with Iterators and Generators     102

Chapter 4: Dictionaries     109

     Item 25: Be Cautious when Relying on Dictionary Insertion Ordering     109

     Item 26: Prefer get over in and KeyError to Handle Missing Dictionary Keys     117

     Item 27: Prefer defaultdict over setdefault to Handle Missing Items in Internal State     122

     Item 28: Know How to Construct Key-Dependent Default Values with __missing__     124

     Item 29: Compose Classes Instead of Deeply Nesting Dictionaries, Lists, and Tuples     127

Chapter 5: Functions     135

     Item 30: Know That Function Arguments Can Be Mutated     135

     Item 31: Return Dedicated Result Objects Instead of Requiring Function Callers to Unpack More Than Three Variables     138

     Item 32: Prefer Raising Exceptions to Returning None     142

     Item 33: Know How Closures Interact with Variable Scope and nonlocal     145

     Item 34: Reduce Visual Noise with Variable Positional Arguments     150

     Item 35: Provide Optional Behavior with Keyword Arguments     153

     Item 36: Use None and Docstrings to Specify Dynamic Default Arguments     157

     Item 37: Enforce Clarity with Keyword-Only and Positional-Only Arguments     161

     Item 38: Define Function Decorators with functools.wraps     166

     Item 39: Prefer functools.partial over lambda Expressions for Glue Functions     169

Chapter 6: Comprehensions and Generators     173

     Item 40: Use Comprehensions Instead of map and filter     173

     Item 41: Avoid More Than Two Control Subexpressions in Comprehensions     176

     Item 42: Reduce Repetition in Comprehensions with Assignment Expressions     178

     Item 43: Consider Generators Instead of Returning Lists     182

     Item 44: Consider Generator Expressions for Large List Comprehensions     184

     Item 45: Compose Multiple Generators with yield from     186

     Item 46: Pass Iterators into Generators as Arguments Instead of Calling the send Method     188

     Item 47: Manage Iterative State Transitions with a Class Instead of the Generator throw Method     195

Chapter 7: Classes and Interfaces     201

     Item 48: Accept Functions Instead of Classes for Simple Interfaces     201

     Item 49: Prefer Object-Oriented Polymorphism over Functions with isinstance Checks     205

     Item 50: Consider functools.singledispatch for Functional-Style Programming Instead of Object-Oriented Polymorphism     210

     Item 51: Prefer dataclasses for Defining Lightweight Classes     217

     Item 52: Use @classmethod Polymorphism to Construct Objects Generically     230

     Item 53: Initialize Parent Classes with super     235

     Item 54: Consider Composing Functionality with Mix-in Classes     240

     Item 55: Prefer Public Attributes over Private Ones     245

     Item 56: Prefer dataclasses for Creating Immutable Objects     250

     Item 57: Inherit from collections.abc Classes for Custom Container Types     260

Chapter 8: Metaclasses and Attributes     265

     Item 58: Use Plain Attributes Instead of Setter and Getter Methods     265

     Item 59: Consider @property Instead of Refactoring Attributes     270

     Item 60: Use Descriptors for Reusable @property Methods     274

     Item 61: Use __getattr__, __getattribute__, and __setattr__ for Lazy Attributes     279

     Item 62: Validate Subclasses with __init_subclass__     285

     Item 63: Register Class Existence with __init_subclass__     293

     Item 64: Annotate Class Attributes with __set_name__     299

     Item 65: Consider Class Body Definition Order to Establish Relationships Between Attributes     303

     Item 66: Prefer Class Decorators over Metaclasses for Composable Class Extensions     310

Chapter 9: Concurrency and Parallelism     319

     Item 67: Use subprocess to Manage Child Processes     320

     Item 68: Use Threads for Blocking I/O; Avoid for Parallelism     324

     Item 69: Use Lock to Prevent Data Races in Threads     330

     Item 70: Use Queue to Coordinate Work Between Threads     333

     Item 71: Know How to Recognize When Concurrency Is Necessary     344

     Item 72: Avoid Creating New Thread Instances for On-Demand Fan-out     349

     Item 73: Understand How Using Queue for Concurrency Requires Refactoring     353

     Item 74: Consider ThreadPoolExecutor When Threads Are Necessary for Concurrency     361

     Item 75: Achieve Highly Concurrent I/O with Coroutines     364

     Item 76: Know How to Port Threaded I/O to asyncio     368

     Item 77: Mix Threads and Coroutines to Ease the Transition to asyncio     381

     Item 78: Maximize Responsiveness of asyncio Event Loops with async-friendly Worker Threads     389

     Item 79: Consider concurrent.futures for True Parallelism     393

Chapter 10: Robustness     399

     Item 80: Take Advantage of Each Block in try/except/else/finally     399

     Item 81: assert Internal Assumptions and raise Missed Expectations     404

     Item 82: Consider contextlib and with Statements for Reusable try/finally Behavior     408

     Item 83: Always Make try Blocks as Short as Possible     412

     Item 84: Beware of Exception Variables Disappearing     414

     Item 85: Beware of Catching the Exception Class     416

     Item 86: Understand the Difference Between Exception and BaseException     419

     Item 87: Use traceback for Enhanced Exception Reporting     424

     Item 88: Consider Explicitly Chaining Exceptions to Clarify Tracebacks     428

     Item 89: Always Pass Resources into Generators and Have Callers Clean Them Up Outside     436

     Item 90: Never Set __debug__ to False     442

     Item 91: Avoid exec and eval Unless Youre Building a Developer Tool     445

Chapter 11: Performance     447

     Item 92: Profile Before Optimizing     448

     Item 93: Optimize Performance-Critical Code Using timeit Microbenchmarks     453

     Item 94: Know When and How to Replace Python with Another Programming Language     458

     Item 95: Consider ctypes to Rapidly Integrate with Native Libraries     462

     Item 96: Consider Extension Modules to Maximize Performance and Ergonomics     467

     Item 97: Rely on Precompiled Bytecode and File System Caching to Improve Startup Time     475

     Item 98: Lazy-Load Modules with Dynamic Imports to Reduce Startup Time     478

     Item 99: Consider memoryview and bytearray for Zero-Copy Interactions with bytes     485

Chapter 12: Data Structures & Algorithms     493

     Item 100: Sort by Complex Criteria Using the key Parameter     493

     Item 101: Know the Difference Between sort and sorted     499

     Item 102: Consider Searching Sorted Sequences with bisect     501

     Item 103: Prefer deque for Producer-Consumer Queues     504

     Item 104: Know How to Use heapq for Priority Queues     509

     Item 105: Use datetime Instead of time for Local Clocks     519

     Item 106: Use decimal When Precision Is Paramount     523

     Item 107: Make pickle Serialization Maintainable with copyreg     526

Chapter 13: Testing and Debugging     533

     Item 108: Verify Related Behaviors in TestCase Subclasses     533

     Item 109: Prefer Integration Tests over Unit Tests     541

     Item 110: Isolate Tests From Each Other with setUp, tearDown, setUpModule, and tearDownModule     547

     Item 111: Use Mocks to Test Code with Complex Dependencies     550

     Item 112: Encapsulate Dependencies to Facilitate Mocking and Testing     559

     Item 113: Use assertAlmostEqual to Control Precision in Floating Point Tests     563

     Item 114: Consider Interactive Debugging with pdb     565

     Item 115: Use tracemalloc to Understand Memory Usage and Leaks     570

Chapter 14: Collaboration     575

     Item 116: Know Where to Find Community-Built Modules     575

     Item 117: Use Virtual Environments for Isolated and Reproducible Dependencies     576

     Item 118: Write Docstrings for Every Function, Class, and Module     582

     Item 119: Use Packages to Organize Modules and Provide Stable APIs     588

     Item 120: Consider Module-Scoped Code to Configure Deployment Environments     593

     Item 121: Define a Root Exception to Insulate Callers from APIs     595

     Item 122: Know How to Break Circular Dependencies     600

     Item 123: Consider warnings to Refactor and Migrate Usage     605

     Item 124: Consider Static Analysis via typing to Obviate Bugs     613

     Item 125: Prefer Open Source Projects for Bundling Python Programs over zipimport and zipapp     621

Index     627

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


H 什么意思 包皮是什么样子图片 led是什么意思 用盐刷牙有什么好处和坏处 考试紧张吃什么药可缓解
为什么会连续两天遗精 拉比是什么意思 什么叫寓言故事 五行缺什么查询 我是什么结构
社保卡是什么样的图片 xl代表什么尺码 吃什么补肺 肝脏钙化灶是什么意思 家五行属什么
老年人尿血是什么原因 心电轴左偏是什么意思 口炎念什么 tea什么意思 衣服最小码是什么字母
言谈举止是什么意思hcv9jop2ns6r.cn 玻璃什么时候传入中国clwhiglsz.com 十二指肠球炎是什么病jingluanji.com 胆汁反流有什么症状wzqsfys.com 梦见打人是什么意思gangsutong.com
兵马俑什么时候发现的hcv8jop3ns5r.cn 挂急诊和门诊有什么区别hcv9jop0ns1r.cn 奇点是什么意思hcv8jop5ns3r.cn 体毛旺盛是什么原因hcv8jop5ns2r.cn 什么样的耳朵hcv9jop5ns0r.cn
咳嗽吃什么食物好得最快最有效hcv8jop0ns6r.cn 为什么白天能看到月亮hcv9jop4ns7r.cn 手麻挂什么科最好hcv9jop6ns0r.cn 划船是什么意思clwhiglsz.com 总胆汁酸高是什么意思hcv8jop9ns4r.cn
雌激素分泌过多是什么原因引起的hcv8jop8ns3r.cn 当令是什么意思hcv7jop5ns4r.cn 用进废退是什么意思fenrenren.com 怀孕一个月有点见红是什么情况hcv8jop8ns0r.cn 咖啡什么牌子的好hcv9jop7ns1r.cn
百度