没有合适的资源?快使用搜索试试~ 我知道了~
首页Python高效编程秘籍:实战技巧与Python 3优化
"《Effective Python》(第二版)是一本备受推崇的Python编程经典教材,专为提升代码效率、实现目标和编写简洁代码而设计。本书在2015年首版的基础上进行了更新和扩展,适用于Python 3环境,无论编程经验丰富的专业人士还是初学者都能从中受益匪浅。 该书得到了众多业界知名人士的高度评价。Wes McKinney,Python Pandas项目的创始人和Ursa Labs的总监,热烈推荐这本书,认为它是跨语言程序员深入了解Python独特特性的权威指南。即使对于资深的Python开发者,如Simon Willison,他在使用Python近二十年后仍然能从书中学习到许多实用技巧,特别是关于Python 3新功能的运用。《Effective Python》充满了实战建议,帮助我们理解社区中所说的“Pythonic”编程风格。 书中不仅涵盖了如何让Python代码运行得更快,比如介绍如何使用`bisect`对排序列表进行高效搜索,还关注代码可读性和错误预防。例如,通过强制使用关键字参数,可以简化函数调用并减少出错可能性。此外,作者还分享了各种优化技术,使读者能够改进代码性能,提高代码质量。 《Effective Python》是一本不可或缺的参考书籍,无论是对Python新手还是寻求提升的专业人员,都能提供实用的编程策略和最佳实践,助你在Python编程旅程中不断进步。"
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/88368364/bg10.jpg)
Preface
The Python programming language has unique strengths and charms
that can be hard to grasp. Many programmers familiar with other
languages often approach Python from a limited mindset instead of
embracing its full expressivity. Some programmers go too far in the
other direction, overusing Python features that can cause big prob-
lems 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 capabilities. Experienced pro-
grammers will learn how to embrace the strangeness of a new tool
with confidence.
My goal is to prepare you to make a big impact with Python.
What This Book Covers
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 second edition of this book is focused exclusively on Python 3
(see Item 1: “Know Which Version of Python You’re Using”), up to and
including version 3.8. Most of the original items from the first edi-
tion have been revised and included, but many have undergone sub-
stantial updates. For some items, my advice has completely changed
between the two editions of the book due to best practices evolving as
Python has matured. If you’re still primarily using Python 2, despite
![](https://csdnimg.cn/release/download_crawler_static/88368364/bg11.jpg)
xviii Preface
its end-of-life on January 1st, 2020, the previous edition of the book
may be more useful to you.
Python takes a “batteries included” approach to its standard library,
in comparison to many other languages that ship with a small
number of common packages and require you to look elsewhere
for important functionality. 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.
Chapter 1: Pythonic Thinking
The Python community has come to use the adjective Pythonic to
describe code that follows a particular style. The idioms of Python
have emerged over time through experience using the language and
working with others. This chapter covers the best way to do the most
common things in Python.
Chapter 2: Lists and Dictionaries
In Python, the most common way to organize information is in a
sequence of values stored in a list. A list’s natural complement is the
dict that stores lookup keys mapped to corresponding values. This
chapter covers how to build programs with these versatile building
blocks.
Chapter 3: Functions
Functions in Python have a variety of extra features that make a
programmer’s life easier. Some are similar to capabilities in other pro-
gramming languages, but many are unique to Python. This chapter
covers how to use functions to clarify intention, promote reuse, and
reduce bugs.
Chapter 4: Comprehensions and Generators
Python has special syntax for quickly iterating through lists, dictio-
naries, and sets to generate derivative data structures. It also allows
for a stream of iterable values to be incrementally returned by a
function. This chapter covers how these features can provide better
performance, reduced memory usage, and improved readability.
Chapter 5: Classes and Interfaces
Python is an object-oriented language. Getting things done in Python
often requires writing new classes and defining how they interact
![](https://csdnimg.cn/release/download_crawler_static/88368364/bg12.jpg)
Preface xix
through their interfaces and hierarchies. This chapter covers how to
use classes to express your intended behaviors with objects.
Chapter 6: Metaclasses and Attributes
Metaclasses and dynamic attributes are powerful Python features.
However, they also enable you to implement extremely bizarre and
unexpected behaviors. This chapter covers the common idioms for
using these mechanisms to ensure that you follow the rule of least
surprise.
Chapter 7: Concurrency and Parallelism
Python makes it easy to write concurrent programs that do many
different things seemingly at the same time. Python can also be used
to do parallel work through system calls, subprocesses, and C exten-
sions. This chapter covers how to best utilize Python in these subtly
different situations.
Chapter 8: Robustness and Performance
Python has built-in features and modules that aid in hardening your
programs so they are dependable. Python also includes tools to help
you achieve higher performance with minimal effort. This chapter
covers how to use Python to optimize your programs to maximize
their reliability and efficiency in production.
Chapter 9: Testing and Debugging
You should always test your code, regardless of what language it’s
written in. However, Python’s dynamic features can increase the risk
of runtime errors in unique ways. Luckily, they also make it easier to
write tests and diagnose malfunctioning programs. This chapter cov-
ers Python’s built-in tools for testing and debugging.
Chapter 10: Collaboration
Collaborating on Python programs requires you to be deliberate about
how you write your code. Even if you’re working alone, you’ll want to
understand how to use modules written by others. This chapter cov-
ers the standard tools and best practices that enable people to work
together on Python programs.
Conventions Used in This Book
Python code snippets in this book are in monospace font and have
syntax highlighting. When lines are long, I use ¯ characters to show
![](https://csdnimg.cn/release/download_crawler_static/88368364/bg13.jpg)
xx Preface
when they wrap. I truncate some snippets with ellipses (... ) to indi-
cate regions where code exists that isn’t essential for expressing the
point. You’ll need to download the full example code (see below on
where to get it) to get these truncated snippets to run correctly on
your computer.
I take some artistic license with the Python style guide in order to
make the code examples better fit the format of a book, or to highlight
the most important parts. I’ve also left out embedded documentation
to reduce the size of code examples. I strongly suggest that you don’t
emulate this in your projects; instead, you should follow the style
guide (see Item 2: “Follow the PEP 8 Style Guide”) and write documen-
tation (see Item 84: “Write Docstrings for Every Function, Class, and
Module”).
Most code snippets in this book are accompanied by the correspond-
ing output from running the code. When I say “output,” I mean console
or terminal output: what you see when running the Python program
in an interactive interpreter. Output sections are in monospace font
and are preceded by a >>> line (the Python interactive prompt). The
idea is that you could type the code snippets into a Python shell and
reproduce the expected output.
Finally, there are some other sections in monospace font that are not
preceded by a >>> line. These represent the output of running pro-
grams besides the normal Python interpreter. These examples often
begin with $ characters to indicate that I’m running programs from a
command-line shell like Bash. If you’re running these commands on
Windows or another type of system, you may need to adjust the pro-
gram names and arguments accordingly.
Where to Get the Code and Errata
It’s useful to view some of the examples in this book as whole
programs without interleaved prose. This also gives you a chance to
tinker with the code yourself and understand why the program works
as described. You can find the source code for all code snippets in
this book on the book’s website at https://effectivepython.com. The
website also includes any corrections to the book, as well as how to
report errors.
![](https://csdnimg.cn/release/download_crawler_static/88368364/bg14.jpg)
Acknowledgments
This book would not have been possible without the guidance,
support, and encouragement from many people in my life.
Thanks to Scott Meyers for the Effective Software Development series.
I first read Effective C++ when I was 15 years old and fell in love with
programming. There’s no doubt that Scott’s books led to my academic
experience and first job. I’m thrilled to have had the opportunity to
write this book.
Thanks to my technical reviewers for the depth and thoroughness
of their feedback for the second edition of this book: Andy Chu, Nick
Cohron, Andrew Dolan, Asher Mancinelli, and Alex Martelli. Thanks
to my colleagues at Google for their review and input. Without all of
your help, this book would have been inscrutable.
Thanks to everyone at Pearson involved in making this second edi-
tion a reality. Thanks to my executive editor Debra Williams for being
supportive throughout the process. Thanks to the team who were
instrumental: development editor Chris Zahn, marketing manager
Stephane Nakib, copy editor Catherine Wilson, senior project editor
Lori Lyons, and cover designer Chuti Prasertsith.
Thanks to everyone who supported me in creating the first edition of
this book: Trina MacDonald, Brett Cannon, Tavis Rudd, Mike Taylor,
Leah Culver, Adrian Holovaty, Michael Levine, Marzia Niccolai, Ade
Oshineye, Katrina Sostek, Tom Cirtin, Chris Zahn, Olivia Basegio,
Stephane Nakib, Stephanie Geels, Julie Nahil, and Toshiaki
Kurokawa. Thanks to all of the readers who reported errors and room
for improvement. Thanks to all of the translators who made the book
available in other languages around the world.
Thanks to the wonderful Python programmers I’ve known and
worked with: Anthony Baxter, Brett Cannon, Wesley Chun, Jeremy
Hylton, Alex Martelli, Neal Norwitz, Guido van Rossum, Andy Smith,
剩余468页未读,继续阅读
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![azw3](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/352d221879d747509c82a753e5345349_quant_galaxy.jpg!1)
rockwood573
- 粉丝: 85
- 资源: 43
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
会员权益专享
最新资源
- 利用迪杰斯特拉算法的全国交通咨询系统设计与实现
- 全国交通咨询系统C++实现源码解析
- DFT与FFT应用:信号频谱分析实验
- MATLAB图论算法实现:最小费用最大流
- MATLAB常用命令完全指南
- 共创智慧灯杆数据运营公司——抢占5G市场
- 中山农情统计分析系统项目实施与管理策略
- XX省中小学智慧校园建设实施方案
- 中山农情统计分析系统项目实施方案
- MATLAB函数详解:从Text到Size的实用指南
- 考虑速度与加速度限制的工业机器人轨迹规划与实时补偿算法
- Matlab进行统计回归分析:从单因素到双因素方差分析
- 智慧灯杆数据运营公司策划书:抢占5G市场,打造智慧城市新载体
- Photoshop基础与色彩知识:信息时代的PS认证考试全攻略
- Photoshop技能测试:核心概念与操作
- Photoshop试题与答案详解
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)