125 Specific Ways to Write Better Python (Effective Software Development Series)
Brett Slatkin

#Python
#Pythonic
#debugging
#testing
#robust
👨💻 کتاب Effective Python یه راهنمای جامع برای تسلط بر هنر برنامهنویسی با پایتونه که ۱۲۵ نکته عملی رو برای نوشتن کدهای بهینهتر، خواناتر و با قابلیت نگهداری بالا بهت یاد میده. پایتون زبان خیلی قدرتمندی هست، اما برای اینکه بتونی از تمام پتانسیلش استفاده کنی، فقط دونستن سینتکس کافی نیست. ویرایش سوم این کتاب، تعداد نکات برتر رو از ۹۰ به ۱۲۵ رسونده تا بتونی از نقاط قوت منحصربهفرد پایتون استفاده کنی و توی تلههای مخفی این زبان نیفتی.
برت اسلاتکین با تکیه بر سالها تجربهاش در گوگل، توصیههای شفاف و کاربردی رو برای برنامهنویسهای تازهکار و باسابقه پایتون آماده کرده. هر بخش از کتاب، بینشی درباره روش "پایتونیک" (Pythonic) بهت میده تا کدهایی بنویسی که نه تنها کار میکنن، بلکه شیک و تمیز هم هستن. چه دنبال ساخت اپلیکیشنهای وب باشی، چه تحلیل داده، اتوماسیون یا آموزش مدلهای هوش مصنوعی، این کتاب مهارتهای لازم رو بهت میده.
🚀 ویژگیهای کلیدی ویرایش سوم
• محتوای گسترده شده: حالا شامل ۱۲۵ راهنمای عملی هست که ۳۵ موردش کاملاً جدیده.
• بهروزرسانی نکات: تمام مطالب بر اساس آخرین ویژگیهای پایتون تا نسخه ۳.۱۳ بازبینی شده.
• فصلهای جدید: بخشهای اضافهای برای ساخت برنامههای قدرتمند با کارایی بالا در نظر گرفته شده.
• مباحث پیشرفته: پوشش عمیقِ ساخت ماژولهای C-extension و کار با کتابخانههای محلی (Native).
• مثالهای کاربردی: کدهای واقعی برای هر نکته آورده شده تا موضوع رو کامل درک کنی.
📑 فهرست مطالب
۱. تفکر پایتونیک (Pythonic Thinking)
۲. رشتهها و اسلایسینگ (Strings and Slicing)
۳. حلقهها و ایتریتورها (Loops and Iterators)
۴. دیکشنریها
۵. توابع
۶. لیستهای درکی و ژنراتورها (Comprehensions and Generators)
۷. کلاسها و اینترفیسها
۸. متاکلاسها و اتریبیوتها
۹. همزمانی و موازیسازی (Concurrency and Parallelism)
۱۰. پایداری و استحکام کد (Robustness)
۱۱. عملکرد و کارایی (Performance)
۱۲. ساختار دادهها و الگوریتمها
۱۳. تست و دیباگ کردن
۱۴. همکاری تیمی (Collaboration)
👥 این کتاب برای چه کسی است؟
بسیاری از برنامهنویسهایی که از زبانهای دیگه میان، با یه ذهنیت محدود سراغ پایتون میرن و از تمام قابلیتهاش استفاده نمیکنن. از اون طرف، بعضیها هم بیش از حد از ویژگیهای پایتون استفاده میکنن که بعداً براشون دردسرساز میشه. این کتاب روی درک عمیق زبان پایتون تمرکز داره؛ برنامهنویسهای تازهکار بهترین متدها رو یاد میگیرن و حرفهایها هم یاد میگیرن چطوری با اعتمادبهنفس از ابزارهای جدید استفاده کنن.
🎓 آنچه یاد خواهید گرفت
هر فصل شامل مجموعهای از آیتمهای مرتبط هست و میتونی بر اساس نیازت بینشون جابجا بشی. هر آیتم راهنمایی میکنه که چیکار کنی، از چی دوری کنی، چطوری تعادل رو رعایت کنی و چرا این انتخاب، بهترین گزینه است. نویسنده نکات رو بر اساس پایتون ۳.۱۳ نوشته و خیلی از توصیهها نسبت به ویرایش قبلی تغییر کرده، چون با پختهتر شدن پایتون در ۵ سال اخیر، بهترین متدها هم تکامل پیدا کردن. همچنین به بستههای استاندارد پایتون که برای هر برنامهنویسی حیاتی هستن هم پرداخته شده.
👨🏫 درباره نویسنده
برت اسلاتکین مهندس نرمافزار ارشد در گوگل (دفتر CTO) هست و روی تکنولوژیهای نوظهور تمرکز داره. اون همبنیانگذار Google Surveys بوده، اولین محصول گوگل کلاود (App Engine) رو لانچ کرده و یکی از سازندگان پروتکل PubSubHubbub هست که همه اینها رو با پایتون انجام داده. برت ۱۹ ساله که به صورت حرفهای پایتون مینویسه و مشارکتهای زیادی در پروژههای متنباز داشته.
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:
Who is this for?
The Python programming language has unique strengths and charms that can be hard to grasp. Many programmers familiar with other languages approach Python from a limited mindset instead of embracing its full capabilities. Some programmers go too far in the other direction, overusing Python features that can cause big problems later.
This book provides insight into the Pythonic way of writing programs: the best way to use Python. It builds on a fundamental understanding of the language that I assume you already have. Novice programmers will learn the best practices of Python’s critical features. Experienced programmers will learn how to embrace a new tool with confidence.
Each chapter in this book contains a broad but related set of items. Feel free to jump between items and follow your interest. Each item contains concise and specific guidance explaining how you can write Python programs more effectively. Items include advice on what to do, what to avoid, how to strike the right balance, and why this is the best choice. Items reference each other to make it easier to fill in the gaps as you read.
This third edition covers the language up through Python version 3.13. This book includes 35 completely new items compared to the second edition. Most of the items from the second edition have been revised and included, but many have undergone substantial updates. For some items, my advice has completely changed due to best practices evolving as Python has matured over the past five years.
Python takes a “batteries included” approach to its standard library. Many of these built-in packages are so closely intertwined with idiomatic Python that they may as well be part of the language specification. The full set of standard modules is too large to cover in this book, but I’ve included the ones that I feel are critical to be aware of and use.
Python also has a vibrant ecosystem of community-built modules that extend the language in valuable ways. Although I mention important packages to know about in various items, this book is not intended to be a thorough reference. Similarly, despite the importance of Python package management, I avoid going into the details about it because it’s rapidly changing and evolving.
Table of Contents
Chapter 1 Pythonic Thinking
Chapter 2 Strings and Slicing
Chapter 3 Loops and Iterators
Chapter 4 Dictionaries
Chapter 5 Functions
Chapter 6 Comprehensions and Generators
Chapter 7 Classes and Interfaces
Chapter 8 Metaclasses and Attributes
Chapter 9 Concurrency and Parallelism
Chapter 10 Robustness
Chapter 11 Performance
Chapter 12 Data Structures and Algorithms
Chapter 13 Testing and Debugging
Chapter 14 Collaboration
Brett Slatkin is a Principal Software Engineer at Google in the Office of the CTO, focusing on emerging technologies. He co-founded Google Surveys, launched Google Cloud’s first product (App Engine), and co-created the PubSubHubbub protocol―all using Python. Brett has been writing Python code professionally for the past 19 years and has made numerous contributions to open-source projects.









