Python is an amazing programming language. It can be applied to almost any programming task, allows for rapid development and debugging, and brings the support of what is arguably the most welcoming user community.

Python是一种了不起的编程语言。 它可以应用于几乎所有编程任务,可以进行快速开发和调试,并可以带来最受欢迎的用户社区的支持。

Getting started with Python is like learning any new skill: it’s important to find a resource you connect with to guide your learning. Luckily, there’s no shortage of excellent books that can help you learn both the basic concepts of programming and the specifics of programming in Python. With the abundance of resources, it can be difficult to identify which book would be best for your situation.

Python入门就像学习任何新技能一样:找到与您联系的资源以指导您的学习很重要。 幸运的是,不乏优秀的书籍可以帮助您学习编程的基本概念和Python编程的细节。 凭借丰富的资源,可能很难确定哪本书最适合您的情况。

In this article, we highlight the best books for learning Python through a collection of book reviews. Each review gives you a taste of the book, the topics covered, and the context used to illustrate those topics. Different books will resonate with different people, depending on the style and presentation of the books, the readers’ backgrounds, as well as other factors.

在本文中,我们通过一系列书评重点介绍了学习Python的最佳书籍。 每次评论都使您对本书有品味,涵盖的主题以及用于说明这些主题的上下文。 根据书籍的样式和呈现方式,读者的背景以及其他因素,不同的书籍会引起不同的人共鸣。

If you are new to Python, any of the introductory books will give you a solid foundation in the basics.


Perhaps you want to learn Python with your kid, or maybe teach Python to a group of kids. Check out the Best Python Books for Kids for resources aimed at a younger audience.

也许您想和您的孩子一起学习Python,或者向一群孩子教Python。 查看针对儿童的最佳Python书籍,以获得针对年轻读者的资源。

As you progress in you Python journey, you will want to dig deeper to maximize the efficiency of your code. The best intermediate and advanced Python books provide insight to help you level up your Python skills, enabling you to become an expert Pythonista.

随着Python旅程的进展,您将需要更深入地挖掘以最大程度地提高代码效率。 最好的中级和高级Python书籍提供了可帮助您提高Python技能的见识,使您成为专家Pythonista。

After reading these reviews, if you still are not sure which book to choose, publishers often provide a sample chapter or section to give you an example of what the book offers. Reading a sample of the book should give you the most representative picture of the author’s pace, style, and expectations.

阅读这些评论后,如果您仍然不确定要选择哪本书,出版商通常会提供示例章节,以举例说明该书的内容。 阅读本书的样本应该可以使您对作者的脚步,风格和期望有最深刻的了解。

Regardless of which book most stands out, consider this anecdote from one of our book reviewers, Steven C. Howell:

无论哪本书最突出,都请考虑一下我们其中一位书评人史蒂文·霍维尔(Steven C. Howell)的轶事:

“A favorite professor once told me, ‘It doesn’t matter which book you read first. It’s always the second one that makes the most sense.’

“一位最喜欢的教授曾经告诉我,'先读哪本书都没关系。 永远是最有意义的第二件事。

I can’t say this has always been the case for me, but I’ve definitely found that a second reference can make all the difference when the first left me puzzled or frustrated.


When learning Python classes, I had difficulty relating to the examples used in the first two books I picked up. It wasn’t until the third book I referred to that the concepts started to click.

在学习Python类时,我很难与我挑选的前两本书中使用的示例相关。 直到我提到的第三本书,这些概念才开始流行。

The important lesson is that if you get stuck or frustrated, and the resources you have are not helping, then don’t give up. Look at another book, search the web, ask on a forum, or just take a break.”

重要的教训是,如果您陷入困境或沮丧,而您所拥有的资源无济于事,那就不要放弃。 看看另一本书,在网上搜索,在论坛上提问,或者休息一下。”

Note: This article contains affiliate links to retailers like Amazon, so you can support Real Python by clicking through and making a purchase on some of the links. Purchasing from one of these links adds no extra cost to you. Affiliate links never influence our editorial decisions in any way.

注意:本文包含指向零售商(如亚马逊)的会员链接,因此您可以通过单击某些链接并进行购买来支持Real Python。 从这些链接之一进行购买不会增加您的额外费用。 会员链接绝不会影响我们的编辑决定。

最好的Python学习书籍 (Best Books for Learning Python)

If you are new to Python, you are likely in one of the following two situations:


  1. You are new to programming and want to start by learning Python.
  2. You have a reasonable amount of programming experience in another language and now want to learn Python.
  1. 您是编程的新手,并且想开始学习Python。
  2. 您有相当多的其他语言编程经验,现在想学习Python。

This section focuses on the first of these two scenarios, with reviews of the books we consider to be the best Python programming books for readers who are new to both programming and Python. Accordingly, these books require no previous programming experience. They start from the absolute basics and teach both general programming concepts as well as how they apply to Python.

本节重点介绍这两种情况中的第一种,并回顾了我们认为对于那些不熟悉编程和Python的读者来说是最好的Python编程书籍。 因此,这些书不需要以前的编程经验。 它们从绝对的基础知识入手,并教授通用的编程概念以及它们如何应用于Python。

Note: If you’re looking for the best Python books for experienced programmers, consider the following selection of books with full reviews in the intro and advanced sections:

注意:如果您正在寻找经验丰富的程序员最好的Python书籍 ,请考虑在介绍部分和高级部分中选择以下具有完整评论的书籍:

  • Think Python: The most basic of this list, Think Python provides a comprehensive Python reference.
  • Fluent Python: While Python’s simplicity lets you quickly start coding, this book teaches you how to write idiomatic Python code, while going into several deep topics of the language.
  • Effective Python: 59 Ways to Write Better Python: This relatively short book is a collection of 59 articles that, similarly to Fluent Python, focus on teaching you how to write truly Pythonic code.
  • Python Cookbook: As a cookbook, this will be a good reference on how to use Python to complete tasks you have done in another language.
  • Think Python :此列表中最基本的,Think Python提供了全面的Python参考。
  • 流利的Python :虽然Python的简单性使您可以快速开始编码,但本书将教您如何编写惯用的Python代码,同时深入探讨该语言的多个主题。
  • 有效的Python:编写更好Python的59种方法 :这本相对较短的书是59篇文章的集合,与Fluent Python类似,它着重于教您如何编写真正的Python代码。
  • Python Cookbook :作为一本食谱,这将是有关如何使用Python完成以另一种语言完成的任务的很好的参考。

Alternatively, you may even prefer to go directly to the official Python Tutorial, a well-written and thorough resource.

另外,您甚至可能更喜欢直接阅读官方的Python教程 ,这是一个精心编写且详尽的参考资料。

Python速成课程 (Python Crash Course)

Eric Matthes (No Starch Press, 2016)


"Python Crash Course" Book Cover

It does what it says on the tin, and it does it really well. The book starts out with a walkthrough of the basic Python elements and data structures, working through variables, strings, numbers, lists, and tuples, outlining how you work with each of them.

它能做到锡上所说的,而且确实做得很好。 本书首先介绍了基本的Python元素和数据结构,并遍历了变量,字符串,数字,列表和元组,并概述了如何使用它们。

Next, if statements and logical tests are covered, followed by a dive into dictionaries.

接下来, if涵盖了陈述和逻辑测试,然后再学习字典。

After that, the book covers user input, while loops, functions, classes, and file handling, as well as code testing and debugging.

之后,本书介绍了用户输入, while循环,函数,类和文件处理以及代码测试和调试。

That’s just the first half of the book! In the second half, you work on three major projects, creating some clever, fun applications.

那只是书的前半部分! 在下半年,您将从事三个主要项目,创建一些聪明,有趣的应用程序。

The first project is an Alien Invasion game, essentially Space Invaders, developed using the pygame package. You design a ship (using classes), then program how to pilot it and make it fire bullets. Then, you design several classes of aliens, make the alien fleet move, and make it possible to shoot them down. Finally, you add a scoreboard and a list of high scores to complete the game.

第一个项目是使用pygame软件包开发的Alien Invasion游戏,本质上是Space Invaders。 您设计了一艘船(使用课程),然后编程如何驾驶它并使它发射子弹。 然后,您设计了几类外星人,使外星人舰队移动,并有可能击落它们。 最后,添加一个记分板和高分列表以完成游戏。

After that, the next project covers data visualization with matplotlib, random walks, rolling dice, and a little bit of statistical analysis, creating graphs and charts with the pygal package. You learn how to download data in a variety of formats, import it into Python, and visualize the results, as well as how to interact with web APIs, retrieving and visualizing data from GitHub and HackerNews.

之后,下一个项目将介绍使用matplotlib ,随机游走,掷骰子和一些统计分析进行数据可视化,并使用pygal软件包创建图形和图表。 您将学习如何下载各种格式的数据,将其导入Python并可视化结果,以及如何与Web API交互,如何从GitHub和HackerNews检索和可视化数据。

The third project walks you through the creation of a complete web application using Django to set up a Learning Log to track what users have been studying. It covers how to install Django, set up a project, design your models, create an admin interface, set up user accounts, manage access controls on a per-user basis, style your entire app with Bootstrap, and then finally deploy it to Heroku.

第三个项目将引导您使用Django创建完整的Web应用程序,以设置学习日志来跟踪用户正在学习的内容。 它介绍了如何安装Django,设置项目,设计模型,创建管理界面,设置用户帐户,按用户管理访问控制,使用Bootstrap设置整个应用程序的样式,然后最终将其部署到Heroku 。

This book is well written and nicely organized. It presents a large number of useful exercises as well as three challenging and entertaining projects that make up the second half of the book. (Reviewed by David Schlesinger.)

这本书写得很好,组织得很好。 它提供了大量有用的练习,以及构成本书后半部分的三个具有挑战性和娱乐性的项目。 (David Schlesinger评论。)

头先Python,第二版 (Head-First Python, 2nd edition)

Paul Barry (O’Reilly, 2016)


"Head-First Python" Book Cover

I really like the Head-First series of books, although they’re admittedly lighter weight in overall content than many of the other recommendations in this section. The trade-off is the that this approach makes the book more user-friendly.

我确实很喜欢Head-First系列丛书,尽管公认它们的整体内容比本节中的许多其他建议要轻。 权衡是这种方法使本书更加人性化。

If you’re the kind of person who likes to learn things one small, fairly self-contained chunk at a time, and you want to have lots of concrete examples and illustrations of the concepts involved, then the Head-First series is for you. The publisher’s website has the following to say about their approach:

如果您是那种喜欢一次学习一个很小的,相当独立的模块的人,并且想要有很多具体的示例和所涉及概念的图解,那么H​​ead-First系列适合您。 发布者的网站对他们的做法有以下说法:

“Based on the latest research in cognitive science and learning theory, Head-First Python uses a visually rich format to engage your mind, rather than a text-heavy approach that puts you to sleep. Why waste your time struggling with new concepts? This multi-sensory learning experience is designed for the way your brain really works.” (Source)

“基于认知科学和学习理论的最新研究,Head-First Python使用一种视觉丰富的格式来吸引您的思想,而不是使文本沉重的方法使您入睡。 为什么要浪费时间在新概念上苦苦挣扎? 这种多感觉学习体验是为您的大脑真正工作的方式而设计的。” (资源)

Chock full of illustrations, examples, asides, and other tidbits, Head-First Python is consistently engaging and easy to read. This book starts its tour of Python by diving into lists and explaining how to use and manipulate them. It then goes into modules, errors, and file handling. Each topic is organized around a unifying project: building a dynamic website for a school athletic coach using Python through a Common Gateway Interface (CGI).

Head-First Python充满了插图,示例,辅助元素和其他花哨的小知识,始终如一地吸引人并且易于阅读。 本书通过深入研究列表并解释如何使用和操纵它们来开始其Python之旅。 然后进入模块,错误和文件处理。 每个主题都围绕一个统一的项目进行组织:通过通用网关接口(CGI)使用Python为学校运动教练构建一个动态网站。

After that, the book spends time teaching you how to use an Android application to interact with the website you created. You learn to handle user input, wrangle data, and look into what’s involved in deploying and scaling a Python application on the web.

之后,这本书花时间教您如何使用Android应用程序与您创建的网站进行交互。 您将学习如何处理用户输入,如何处理数据以及如何在网络上部署和扩展Python应用程序。

While this book isn’t as comprehensive as some of the others, it covers a good range of Python tasks in a way that’s arguably more accessible, painless, and effective. This is especially true if you find the subject of writing programs somewhat intimidating at first.

尽管本书没有其他本书那么全面,但它以一种更容易理解,更轻松,更有效的方式涵盖了许多Python任务。 如果您一开始发现编写程序的主题有些令人生畏,则尤其如此。

This book is designed to guide you through any challenge. While the content is more focused, this book has plenty of material to keep you busy and learning. You will not be bored. If you find most programming books to be too dry, this could be an excellent book for you to get started in Python. (Reviewed by David Schlesinger and Steven C. Howell.)

本书旨在指导您应对任何挑战。 当内容更加集中时,本书提供了大量材料,可让您保持忙碌和学习。 您不会感到无聊。 如果您发现大多数编程书籍都过于枯燥,那么这可能是一本很好的入门Python书籍。 (由David Schlesinger和Steven C. Howell审查。)

使用Python发明自己的电脑游戏,第4版 (Invent Your Own Computer Games with Python, 4th edition)

Al Sweigart (No Starch, 2017)

Al Sweigart(No Starch,2017)

"Invent Your Own Computer Games with Python" Book Cover

If games are your thing, or you even have a game idea of your own, this would be the perfect book to learn Python. In this book, you learn the fundamentals of programming and Python with the application exercises focused on building classic games.

如果您喜欢玩游戏,或者甚至有自己的游戏创意,那么这将是学习Python的完美书。 在本书中,您将通过专注于构建经典游戏的应用练习来学习编程和Python的基础知识。

Starting with an introduction to the Python shell and the REPL loop, followed by a basic “Hello, World!” script, you dive right into making a basic number-guessing game, covering random numbers, flow control, type conversion, and Boolean data. After that, a small joke-telling script is written to illustrate the use of print statements, escape characters, and basic string operations.

首先介绍Python Shell和REPL循环,然后介绍基本的“ Hello,World!”。 脚本,您将直接制作一个基本的猜数字游戏,内容涵盖随机数,流控制,类型转换和布尔数据。 之后,编写了一个小讲笑话的脚本来说明打印语句,转义字符和基本字符串操作的用法。

The next project is a text-based cave exploration game, Dragon’s Realm, which introduces you to flowcharts and functions, guides you through how to define your own arguments and parameters, and explains Boolean operators, global and local scope, and the sleep() function.

下一个项目是基于文本的洞穴探险游戏Dragon's Realm,它向您介绍流程图和函数,指导您如何定义自己的参数和参数,并解释布尔运算符,全局和局部作用域以及sleep()功能。

After a brief detour into how to debug your Python code, you next implement the game of Hangman, using ASCII artwork, while learning about lists, the in operator, methods, elif statements, the random module, and a handful of string methods.

在简要介绍了如何调试Python代码之后,接下来,您将使用ASCII图形来实现Hangman游戏,同时了解列表, in运算符,方法, elif语句, random模块和一些字符串方法。

You then extend the Hangman game with new features, like word lists and difficulty levels, while learning about dictionaries, key-value pairs, and assignment to multiple variables.


Your next project is a Tic-Tac-Toe game, which introduces some high-level artificial intelligence concepts, shows you how to short-circuit evaluation in conditionals, and explains the None value as well as some different ways of accessing lists.


Your journey through the rest of the book proceeds in a similar vein. You’ll learn nested loops while building a Mastermind-style number guessing game, Cartesian coordinates for a Sonar Hunt game, cryptography to write a Caesar cipher, and artificial intelligence when implementing Reversi (also known as Othello), in which the computer can play against itself.

您浏览本书其余部分的过程与此类似。 在构建Reversi(也称为Othello)时,您将在学习Mastermind风格的数字猜谜游戏,Carsonian坐标用于Sonar Hunt游戏,笛卡尔坐标编写凯撒密码以及人工智能时学习嵌套循环。反对自己。

After all of this, there’s a dive into using graphics for your games with PyGame: you’ll cover how to animate the graphics, manage collision detection, as well as use sounds, images, and sprites. To bring all these concepts together, the book guides you through making a graphical obstacle-dodging game.

在完成所有这些工作之后,我们将深入研究如何在PyGame中为游戏使用图形:将介绍如何对图形进行动画处理,管理碰撞检测以及如何使用声音,图像和精灵。 为了将所有这些概念融合在一起,本书将指导您完成图形化的躲避障碍游戏。

This book is well done, and the fact that each project is a self-contained unit makes it appealing and accessible. If you’re someone who likes to learn by doing, then you’ll enjoy this book.

这本书做得很好,每个项目都是一个独立的单元,这一事实使它具有吸引力并易于使用。 如果您是一个喜欢边做边学的人,那么您会喜欢这本书的。

The fact that this book introduces concepts only as needed can be a possible disadvantage. While it’s organized more as a guide than a reference, the broad range of contents taught in the context of familiar games makes this one of the best books for learning Python. (Reviewed by David Schlesinger.)

本书仅根据需要引入概念的事实可能是不利的。 尽管它的组织结构更多是作为参考而非参考,但它在熟悉的游戏环境中教授的广泛内容使其成为学习Python的最佳书籍之一。 (David Schlesinger评论。)

Think Python:如何像计算机科学家一样思考,第二版 (Think Python: How to Think Like a Computer Scientist, 2nd edition)

Allen B. Downey (O’Reilly, 2015)

艾伦·唐尼(Allen B.Downey)(奥莱利,2015年)

"Think Python: How to Think Like a Computer Scientist" Book Cover

If learning Python by creating video games is too frivolous for you, consider Allen Downey’s book Think Python, which takes a much more serious approach.

如果通过创建视频游戏来学习Python太琐碎,请考虑Allen Downey的书Think Python,该书采用了更为严肃的方法。

As the title says, the goal of this book is to teach you how coders think about coding, and it does a good job of it. Compared to the other books, it’s drier and organized in a more linear way. The book focuses on everything you need to know about basic Python programming, in a very straightforward, clear, and comprehensive way.

就像标题所说的那样,本书的目的是教您编码人员如何思考编码,并且它做得很好。 与其他书籍相比,它更干燥,更线性。 本书以非常直接,清晰和全面的方式,集中了您需要了解的有关基本Python编程的所有知识。

Compared to other similar books, it doesn’t go quite as deep into some of the more advanced areas, instead covering a wider range of material, including topics the other books don’t go anywhere near. Examples of such topics include operator overloading, polymorphism, analysis of algorithms, and mutability versus immutability.

与其他类似书籍相比,它没有深入到某些更高级的领域,而是涵盖了更广泛的材料,包括其他书籍所没有涉及的主题。 此类主题的示例包括运算符重载,多态性,算法分析以及可变性与不变性。

Previous versions were a little light on exercises, but the latest edition has largely corrected this shortcoming. The book contains four reasonably deep projects, presented as case studies, but overall, it has fewer directed application exercises compared to many other books.

先前的版本对练习的影响不大,但最新版本已在很大程度上纠正了这一缺点。 这本书包含四个相当深入的项目,以案例研究的形式呈现,但总体而言,与许多其他书籍相比,它的定向应用练习更少。

If you like a step-by-step presentation of just the facts, and you want to get a little additional insight into how professional coders look at problems, this book is a great choice. (Reviewed by David Schlesinger and Steven C. Howell.)

如果您只想逐步介绍事实,并且希望对专业编码人员如何看待问题有更多的了解,那么本书是一个不错的选择。 (由David Schlesinger和Steven C. Howell审查。)

物理中的有效计算:Python研究领域指南 (Effective Computation in Physics: Field Guide to Research with Python)

Anthony Scopatz, Kathryn D. Huff (O’Reilly, 2015)

Anthony Scopatz,Kathryn D.Huff(O'Reilly,2015年)

Effective Computation in Physics

This is the book I wish I had when I was first learning Python.


Despite its name, this book is an excellent choice for people who don’t have experience with physics, research, or computational problems.


It really is a field guide for using Python. On top of actually teaching you Python, it also covers the related topics, like the command-line and version control, as well as the testing and deploying of software.

它确实是使用Python的现场指南。 除了实际教您使用Python之外,它还涵盖了相关主题,例如命令行和版本控制以及软件的测试和部署。

In addition to being a great learning resource, this book will also serve as an excellent Python reference, as the topics are well organized with plenty of interspersed examples and exercises.


The book is divided into four aptly named sections: Getting Started, Getting it Done, Getting it Right, and Getting it Out There.


The Getting Started section contains everything you need to hit the ground running. It begins with a chapter on the fundamentals of the bash command-line. (Yes, you can even install bash for Windows.) The book then proceeds to explain the foundations of Python, hitting on all the expected topics: operators, strings, variables, containers, logic, and flow control. Additionally, there is an entire chapter dedicated to all the different types of functions, and another for classes and object-oriented programming.

《入门指南》部分包含了全面启动所需的一切。 它从有关bash命令行基础知识的一章开始。 (是的,您甚至可以为Windows安装bash 。)然后,本书继续解释Python的基础,涉及所有预期的主题:运算符,字符串,变量,容器,逻辑和流控制。 此外,有一整章专门讨论所有不同类型的函数,另一章则涉及类和面向对象的编程。

Building on this foundation, the Getting it Done section moves into the more data-centric area of Python. Note that this section, which takes up approximately a third of the book, will be most applicable to scientists, engineers, and data scientists. If that is you, enjoy. If not, feel free to skip ahead, picking out any pertinent sections. But be sure to catch the last chapter of the section because it will teach you how to deploy software using pip, conda, virtual machines, and Docker containers.

在此基础上,“完成”部分移至以数据为中心的Python区域。 请注意,本部分约占本书的三分之一,将最适用于科学家,工程师和数据科学家。 如果是您,请尽情享受。 如果不是,请随时跳过,选择所有相关章节。 但是一定要赶上本节的最后一章,因为它将教您如何使用pip,conda,虚拟机和Docker容器部署软件。

For those of you who are interested in working with data, the section begins with a quick overview of the essential libraries for data analysis and visualization. You then have a separate chapter dedicated to teaching you the topics of regular expressions, NumPy, data storage (including performing out-of-core operations), specialized data structures (hash tables, data frames, D-trees, and k-d trees), and parallel computation.

对于那些对数据感兴趣的人,本节从快速概述数据分析和可视化的基本库开始。 然后,您将有单独的一章专门介绍正则表达式,NumPy,数据存储(包括执行核外操作),专用数据结构(哈希表,数据帧,D树和kd树),和并行计算。

The Getting it Right section teaches you how to avoid and overcome many of the common pitfalls associated with working in Python. It begins by extending the discussion on deploying software by teaching you how to build software pipelines using make. You then learn how to use Git and GitHub to track, store, and organize your code edits over time, a process known as version control. The section concludes by teaching you how to debug and test your code, two incredibly valuable skills.

正确入门部分教您如何避免和克服与使用Python相关的许多常见陷阱。 它通过教您如何使用make来构建软件管道来扩展有关软件部署的讨论。 然后,您将学习如何使用Git和GitHub跟踪,存储和组织随时间推移进行的代码编辑,此过程称为版本控制。 本节以教您如何调试和测试代码为结束,这是两项非常宝贵的技能。

The final section, Getting it Out There, focuses on effectively communicating with the consumers of your code, yourself included. It covers the topics of documentation, markup languages (primarily LaTeX), code collaboration, and software licenses. The section, and book, concludes with a long list of scientific Python projects organized by topic.

最后一部分,“深入了解”,重点在于与代码使用者(包括您自己)进行有效的通信。 它涵盖了文档,标记语言(主要是LaTeX),代码协作和软件许可证的主题。 本节和本书以按主题组织的一系列科学Python项目作为结尾。

This book stands out because, in addition to teaching all the fundamentals of Python, it also teaches you many of the technologies used by Pythonistas. This is truly one of the best books for learning Python.

这本书之所以与众不同,是因为除了教授Python的所有基础知识之外,它还教您了Pythonistas使用的许多技术。 这确实是学习Python的最佳书籍之一。

It also serves as a great reference, will a full glossary, bibliography, and index. The book definitely has a scientific Python spin, but don’t worry if you do not come from a scientific background. There are no mathematical equations, and you may even impress your coworkers when they see you are on reading up on Computational Physics! (Reviewed by Steven C Howell.)

它也可以作为完整的词汇表,参考书目和索引的重要参考。 这本书绝对具有科学的Python特色,但是如果您不具有科学背景,请不要担心。 没有数学方程式,当您的同事看到您正在阅读《计算物理》时,您甚至会打动他们! (由Steven C Howell评论。)

艰苦学习Python 3 (Learn Python 3 the Hard Way)

Zed A. Shaw (Addison-Wesley, 2016)

Zed A.Shaw(Addison-Wesley,2016年)

"Learn Python 3 The Hard Way" Book Cover

Learn Python the Hard Way is a classic. I’m a big fan of the book’s approach. When you learn “the hard way,” you have to:

艰难地学习Python是经典之作。 我非常喜欢这本书的方法。 当您学习“艰难的方式”时,您必须:

  1. Type in all the code yourself
  2. Do all the exercises
  3. Find your own solutions to problems you run into
  1. 自己输入所有代码
  2. 做所有的练习
  3. 为遇到的问题找到自己的解决方案

The great thing about this book is how well the content is presented. Each chapter is clearly presented. The code examples are all concise, well constructed, and to the point. The exercises are instructive, and any problems you run into will not be at all insurmountable. Your biggest risk is typographical errors. Make it through this book, and you’ll definitely no longer be a beginner at Python.

本书的优点在于内容的呈现方式。 每章都有清楚的介绍。 这些代码示例都简洁明了,结构精巧且切合实际。 这些练习是有启发性的,您遇到的任何问题都将是无法克服的。 您最大的风险是印刷错误。 通过这本书,您肯定不再是Python的初学者。

Don’t let the title put you off. The “hard way” turns out to be the easy way if you take the long view. Nobody loves typing a lot of stuff in, but that’s what programming actually involves, so it’s good to get used to it from the start. One nice thing about this book is that it has been refined through several editions now, so any rough edges have been made nice and smooth by now.

不要让标题让你失望。 如果您放眼长远,那么“艰难的道路”将变成简单的道路。 没有人喜欢输入很多东西,但这实际上是编程所涉及的,因此从一开始就习惯它是很好的。 关于这本书的一件好事是,它已经通过多个版本进行了改进,因此,到现在为止,任何粗糙的边缘都变得更加美观和流畅。

The book is constructed as a series of over fifty exercises, each building on the previous, and each teaching you some new feature of the language. Starting from Exercise 0, getting Python set up on your computer, you begin writing simple programs. You learn about variables, data types, functions, logic, loops, lists, debugging, dictionaries, object-oriented programming, inheritance, and packaging. You even create a simple game using a game engine.

本书是由五十多个练习组成的一系列练习 ,每个练习都基于先前的练习 ,并且每个练习都为您提供了该语言的一些新功能。 从练习0开始,在计算机上安装Python,开始编写简单的程序。 您将了解变量,数据类型,函数,逻辑,循环,列表,调试,字典,面向对象的编程,继承和打包。 您甚至可以使用游戏引擎创建一个简单的游戏。

The next sections cover concepts like automated testing, lexical scanning on user input to parse sentences, and the lpthw.web package, to put your game up on the web.

接下来的lpthw.web节将介绍诸如自动测试,对用户输入进行词法扫描以分析句子以及lpthw.web软件包等概念 ,以将您的游戏发布到网络上。

Zed is an engaging, patient writer who doesn’t gloss over the details. If you work through this book the right way—the “hard way,” by following up on the study suggestions provided throughout the text as well as the programming exercises—you’ll be well beyond the beginner programmer stage when you’ve finished. (Reviewed by David Schlesinger.)

Zed是一位耐心而耐心的作家,他不掩饰细节。 如果您以正确的方式(“硬性方式”)来完成本书的学习,并遵循全文中提供的学习建议以及编程练习,那么当您完成本书时,您将远远超出了初学者的阶段。 (David Schlesinger评论。)

Note: Of all the books included in this article, this is the only with somewhat mixed reviews. The Stack Overflow (SO) community has compiled a list of 22 complaints prefaced with the following statement:

注意:在本文包含的所有书籍中,这是仅有的几本评论混杂的书籍。 堆栈溢出(SO)社区已编译了22条投诉列表,并以以下声明开头:

“We noticed a general trend that users using [Learn Python the Hard Way] post questions that don’t make a lot of sense both on SO and in chat. This is due to the structure and techniques used in the book.” (Source)

“我们注意到一种普遍的趋势,即使用[以困难的方式学习Python]的用户发布的问题在SO和聊天中都没有多大意义 。 这是由于本书中使用的结构和技术。” (资源)

They provide their own list of recommended tutorials, which includes the following:

他们提供了自己的推荐教程列表 ,其中包括以下内容:

Despite the negative criticism toward Learn Python the Hard Way, David Schlesinger and Amazon reviewers agree that the book is worthwhile, though you probably want to supplement your library with another Python book that could serve more as a reference. Also, be sure to do your due diligence before posting questions to Stack Overflow, as that community can be somewhat abrasive at times.

尽管对“艰难地学习Python”表示了负面批评,但David Schlesinger和Amazon评论家都认为这本书是值得的,尽管您可能想用另一本Python书籍来补充您的图书馆,以作为更多参考。 另外,在向Stack Overflow发布问题之前,请务必进行尽职调查,因为该社区有时可能会有些磨擦。

真正的Python课程,第1部分 (Real Python Course, Part 1)

Real Python Team (Real Python, 2017)

Real Python团队(Real Python,2017)

Real Python Logo

This eBook is the first of three (so far) in the Real Python course series. It was written with the goal of getting you up and running, and it does a great job at achieving this goal. The book is a mix of explanatory prose, example code, and review exercises. The interspersed review exercises solidify your learning by letting you immediately apply what you’ve learned.

这本电子书是Real Python课程系列中的三本(迄今为止)的第一本。 编写该文档的目的是使您入门和运行,并且在实现该目标方面做得很好。 本书混合了解释性散文,示例代码和复习练习。 散布的复习练习可让您立即应用所学内容,从而巩固您的学习经验。

As with the previous books, clear instructions are provided up front for getting Python installed and running on your computer. After the setup section, rather than giving a dry overview of data types, Real Python simply starts with strings and is actually quite thorough: you learn string slicing before you hit page 30.

与以前的书籍一样,为在计算机上安装Python和在其上运行而预先提供了明确的说明。 在设置部分之后,Real Python并没有全面介绍数据类型,而是简单地从字符串开始,并且实际上是非常全面的:您在点击第30页之前就学习了字符串切片。

Then the book gives you a good sense of the flavor of Python by showing you how to play with some of the class methods that can be applied. Next, you learn to write functions and loops, use conditional logic, work with lists and dictionaries, and read and write files.

然后,这本书通过向您展示如何使用一些可以应用的类方法,使您对Python的风格有很好的了解。 接下来,您将学习编写函数和循环,使用条件逻辑,使用列表和字典以及读取和写入文件。

Then things get really fun! Once you’ve learned to install packages with pip (and from source), Real Python covers interacting with and manipulating PDF files, using SQL from within Python, scraping data from web pages, using numpy and matplotlib to do scientific computing, and finally, creating graphical user interfaces with EasyGUI and tkinter.

然后事情变得很有趣! 一旦学会了使用pip (和从源代码)安装软件包,Real Python便涵盖了与Python文件进行交互和处理,使用Python中SQL,从网页中抓取数据,使用numpymatplotlib进行科学计算,最后,创建具有图形用户界面EasyGUItkinter

What I like best about Real Python is that, in addition to covering the basics in a thorough and friendly way, the book explores some more advanced uses of Python that none of the other books hit on, like web-scraping. There are also two additional volumes, which go into more advanced Python development. (Reviewed by David Schlesinger.)

我最喜欢Real Python的地方在于,除了以彻底和友好的方式介绍基础知识外,这本书还探索了Python的一些更高级的用法,而其他任何书籍都没有涉及到Python,例如网络抓取。 另外还有两卷,这些卷进入了更高级的Python开发。 (David Schlesinger评论。)

Disclaimer: I first started using the Real Python books several years ago, when they were still in beta. I thought then—and still think now—that they’re one of the best resources available to learn the Python language and several ways it can be used. My gig writing articles on the Real Python web site is a much more recent development, and my review is completely independent. — David

免责声明:几年前,我还开始使用Real Python书籍,当时它们还处于测试阶段。 我当时(现在仍然认为)认为它们是学习Python语言以及使用它的几种方法的最佳资源之一。 我在Real Python网站上写的演出是一个较新的进展,而我的评论是完全独立的。 - 大卫

最佳儿童书籍 (Best Python Books for Kids)

The following books are aimed at adults interested in teaching kids to code, while possibly learning it themselves along the way. Both of these books are recommended for kids as young as 9 or 10, but they are great for older kids as well.

以下书籍针对有兴趣教孩子们编码的成年人,同时也有可能自己学习编码。 这两本书都推荐给9岁或10岁的孩子使用,但它们也适合年龄较大的孩子。

It’s important to note that these books are not meant to be just handed to a kid, depending on their age. They would be ideal for a parent who wanted to learn Python alongside their child.

重要的是要注意,这些书并不仅仅取决于孩子的年龄,而是要交给他们的。 对于希望与孩子一起学习Python的父母来说,它们是理想的选择。

适用于儿童的Python:有趣的编程入门 (Python for Kids: A Playful Introduction to Programming)

Jason R. Briggs (No Starch, 2013)


"Python for Kids: A Playful Introduction to Programming" Book Cover

“Playful” is right! This is a fun book for all ages, despite its title. It provides a clear, easy to follow, introduction to Python programming. It’s profusely illustrated, the examples are straightforward and clearly presented, and it’s a solid guide for someone who wants to get a good grounding in the basics, plus a little more.

“好玩”是对的! 尽管它的标题如此,但它是所有年龄段的一本有趣的书。 它提供了清晰,易于理解的Python编程介绍。 它被充分地说明,示例简单明了,呈现清晰,对于那些希望在基础知识上有更多基础的人来说,它是一个可靠的指南。

The book begins with an excellent, detailed guide to getting Python installed on your system, whether that’s Windows, OS X, or Ubuntu Linux. It then proceeds to introduce the Python shell and how it can be used as a simple calculator. This serves to introduce some basic concepts like variables and arithmetic operation.

本书从出色的详细指南开始,介绍了如何在系统(无论是Windows,OS X还是Ubuntu Linux)上安装Python。 然后继续介绍Python shell以及如何将其用作简单的计算器。 这有助于介绍一些基本概念,例如变量和算术运算。

Next, iterables are tackled, and the chapter works its way progressively through strings, lists, tuples, and dictionaries.


Once that’s accomplished, the Python turtle library is used to begin working with turtle graphics, a popular framework for teaching children to code. From there, the book progresses through conditional statements, loops, functions, and modules.

一旦完成,Python turtle库就可以开始使用乌龟图形了,这是一个流行的框架,可以教孩子们编写代码。 从这本书开始,逐步学习条件语句,循环,函数和模块。

Classes and objects are covered, followed by a truly excellent section on Python’s built-in functions, and then a section on a number of useful Python libraries and modules. Turtle graphics are revisited in greater detail, after which the book introduces tkinter for creating user interfaces, better graphics, and even animations.

涵盖了类和对象,接着是一个关于Python内置函数的真正优秀的部分,然后是有关许多有用的Python库和模块的部分。 进一步详细地介绍了龟图形,然后在书中介绍了tkinter来创建用户界面,更好的图形甚至动画。

This concludes part 1 of the book, “Learning to Program,” with the remainder focused on building two fun application projects. The first project is to build a single-player version of Pong, called Bounce! This integrates the programming concepts of functions, classes, and control flow, together with the tasks of creating an interface using tkinter, illustrating to the canvas, performing geometric calculations, and using event bindings to create interactivity.

至此,本书“学习编程”的第1部分结束了,其余部分着重于构建两个有趣的应用程序项目。 第一个项目是构建名为Bounce的单人游戏Pong ! 这整合了功能,类和控制流的编程概念,以及使用tkinter创建界面,向画布进行说明,执行几何计算以及使用事件绑定创建交互性的任务。

In the second project, you build a side-scrolling video game, Mr. Stickman Races for the Exit. This game applies many of the same concepts and tasks as Bounce! but with more depth and increased complexity. Along the way, you also get introduced to the open source image manipulation program GIMP, used to create your game’s assets. The book gets an amazing amount of mileage out of these two games, and getting them working is both instructive and a lot of fun.

在第二个项目中,您将制作一个侧卷式视频游戏,Stickman先生为出口而战。 此游戏应用了许多与Bounce相同的概念和任务! 但具有更大的深度和复杂性。 在此过程中,还将介绍用于创建游戏资产的开源图像处理程序GIMP 。 这本书从这两个游戏中获得了惊人的成绩,让它们正常工作既有启发性又很有趣。

I really like this book. Whether you are young, or just young at heart, you will enjoy this book if you are looking for a fun, approachable, introduction to Python and programming. (Reviewed by David Schlesinger and Steven C. Howell.)

我真的喜欢这本书。 无论您是年轻还是内心年轻,如果您正在寻找有趣,平易近人的Python和编程入门,都将喜欢这本书。 (由David Schlesinger和Steven C. Howell审查。)

教孩子们编码:Python编程的亲子指南 (Teach Your Kids to Code: A Parent-Friendly Guide to Python Programming)

Bryson Payne (No Starch, 2015)


"Teach Your Kids to Code: A Parent-Friendly Guide to Python Programming" Book Cover

This book is similar to Python for Kids but intended more for an adult working with a child (or children) to learn to code, as the title suggests. One thing that sets this book apart from most introductory books is the use of color and illustrations on almost every page. The book is well written and presents learning to code as a way to teach children problem-solving skills.

这本书类似于Python for Kids,但正如书名所示,该书的目的更多的是与孩子一起工作的成年人(一个或多个孩子)学习编码。 这本书与大多数入门书籍不同的一件事是几乎每页上都使用了彩色和插图。 这本书写得很好,并介绍了学习编码作为教孩子解决问题技能的一种方式。

As is commonly the case, this book begins with a Python installation guide. Compared to Python for Kids, the guide in this book is more cursory but completely adequate.

通常,这本书从Python安装指南开始。 与Python for Kids相比,本书中的指南更粗略,但完全足够。

The first activity is, again, turtle graphics. A number of basic variations on drawing a rotated square are presented—without a lot of underlying explanation, initially—just to introduce the general concepts, but by the end of the section, you’ll have been provided with a pretty good understanding of the basics.

同样,第一个活动是乌龟图形。 给出了一些关于绘制旋转正方形的基本变体(最初没有很多底层解释),只是为了介绍一般概念,但是到本节结束时,您将对模板有一个很好的理解。基本。

Next, calculations, variables, and mathematics in Python are explained. Once strings have been covered, the book brings all of that back into turtle graphics to enhance and explore the work that was done earlier. By this point, the code explanations are extremely clear, with explicit line-by-line details. You’d have a hard time misunderstanding any of the code presented.

接下来,解释Python中的计算,变量和数学。 覆盖字符串后,本书将所有内容重新带入海龟图形中,以增强和探索之前完成的工作。 至此,代码解释非常清晰,并带有逐行的详细信息。 您将很难理解所提供的任何代码。

Lists are explored next, as is the eval() function. Loops are introduced and then used to create increasingly complex graphics with the turtle. Conditional expressions come next, along with Boolean logic and operators.

接下来是列表,以及eval()函数。 引入了循环,然后将其用于与乌龟一起创建越来越复杂的图形。 接下来是条件表达式,以及布尔逻辑和运算符。

The random library is introduced with a guessing game and randomly placed spirals made with turtle graphics. You explore randomness further by implementing rolling dice and picking cards, which leads up to you creating the games Yahtzee and War.

random库是由一个猜谜游戏引入的,并由乌龟图形随机放置螺旋。 您可以通过实现掷骰子和领料卡来进一步探索随机性,从而最终创建出Yahtzee和War游戏。

Functions, more advanced graphics, and user interaction are investigated next.


The book then branches off to cover using PyGame to create even more advanced graphics and animations, and then user interaction to create a very simple drawing program.


At this point, you have all the tools to create some real games. Development of both a full-featured version of Pong and a bubble-popping game are presented. Both provide enough depth to pose some challenges and maintain interest.

至此,您已经拥有创建一些真实游戏的所有工具。 介绍了功能齐全的Pong版本和泡泡游戏的开发过程。 两者都提供足够的深度来提出一些挑战并保持兴趣。

What I like best about this book is its large number of programming challenges, as well as the excellent summaries at the end of each chapter reminding you what was covered. If you and your child are interested in programming, this book should take both of you a good distance, and you’ll have a lot of fun. As the author, Dr. Bryson Payne, said in his recent TEDx talk, “Step out of your comfort zone, and become literate in the language of technology.” (Reviewed by David Schlesinger and Steven C. Howell.)

对于本书,我最喜欢的是它面临的大量编程挑战,以及每章结尾的出色总结,使您想起了所学内容。 如果您和您的孩子对编程感兴趣,那么这本书对你们俩都应该有很大的帮助,并且您会感到很多乐趣。 正如作者Bryson Payne博士在他最近的TEDx演讲中所说 :“走出舒适区,并精通技术语言。” (由David Schlesinger和Steven C. Howell审查。)

最佳中级和高级Python书籍 (Best Intermediate and Advanced Python Books)

Knowing Python is one thing. Knowing what’s Pythonic takes practice. Sometimes Python’s low barrier to entry gives people the mistaken idea that the language is less capable than other languages, that style does not matter, or that best practices are only a matter of preference. Have you ever seen Python code that looked like C or Fortran?

了解Python是一回事。 知道什么是Pythonic需要实践。 有时,Python的入门门槛低,使人误以为该语言比其他语言功能更弱,样式无关紧要,或者最佳实践只是偏好问题。 您是否看过看起来像C或Fortran的Python代码?

Learning how to use Python effectively requires some understanding of what Python is doing under the hood. Pythonic programming takes advantage of how the Python language is implemented to maximize the efficiency of your code.

学习如何有效地使用Python需要对Python的幕后工作有一些了解。 Pythonic编程利用Python语言的实现方式来最大化您的代码效率。

Fortunately, there are some excellent books, packed with expert guidance, aimed to help you take what you’ve learned and level up your skills. Any of the books in this section will give you a deeper understanding of Python programming concepts and teach you how to write developer-style Python code. Note that these are by no means introductory books. They do not include the basics of getting started. These books will be helpful if you are already coding in Python and want to further hone your skills on your path to becoming a serious Pythonista.

幸运的是,这里有一些优秀的书籍,并附有专家指导,旨在帮助您掌握所学知识并提高技能。 本节中的任何书籍都将使您对Python编程概念有更深入的了解,并教您如何编写开发人员风格的Python代码。 请注意,这些绝不是入门书籍。 它们不包括入门基础。 如果您已经在使用Python进行编码,并希望在成为一名认真的Pythonista的道路上进一步磨练自己的技能,那么这些书将对您有所帮助。

Python技巧:一系列很棒的Python功能 (Python Tricks: A Buffet of Awesome Python Features)

Dan Bader (dbader.org, 2017)


"Python Tricks" Book Cover

This book illustrates valuable lesser-known Python features and best practices, written to help you gain a deeper understanding of Python. Each of the 43 subsections presents a different concept, referred to as a Python Trick, with discussion and easy-to-digest code examples illustrating how you can take advantage of that concept.

本书说明了鲜为人知的宝贵Python功能和最佳实践,旨在帮助您更深入地了解Python。 43个小节中的每个小节都提出了一个不同的概念,称为Python Trick,并提供了讨论和易于理解的代码示例,这些示例说明了如何利用该概念。

The book’s content is broken into the following sections:


  • Patterns for Cleaner Python
  • Effective Functions
  • Classes & OOP
  • Common Data Structures in Python
  • Looping & Iteration
  • Dictionary Tricks
  • Pythonic Productivity Techniques
  • 清洁Python的模式
  • 有效功能
  • 类和面向对象
  • Python中的通用数据结构
  • 循环与迭代
  • 字典技巧
  • Pythonic生产力技术

As it says on the cover, the content is organized as “A Buffet,” with each subsection being a self-contained topic, with a brief introduction, examples, discussion, and list of Key Takeaways. As such, you should feel free to jump around to whichever sections are the most appealing.

就像封面上所说的那样,内容组织为“自助餐”,每个小节都是独立的主题,并提供简要介绍,示例,讨论和要点。 因此,您可以随意跳转到最吸引人的部分。

In addition to the book, I particularly enjoyed the 12 Bonus Videos that are available when you purchase this as an eBook. They have an average length of 11 minutes, perfect for watching during lunch. Each video illustrates a different concept using clear and concise code examples that are simple to reproduce. While some of the videos covered familiar concepts, they still provided interesting insight without dragging on. (Reviewed by Steven C. Howell.)

除了这本书,我特别喜欢当您以电子书形式购买时可获得的12个奖励视频。 平均长度为11分钟,非常适合在午餐时间观看。 每个视频都使用清晰,简洁的代码示例(易于复制)说明了不同的概念。 尽管其中一些视频涵盖了熟悉的概念,但它们仍然提供了有趣的见解而不会拖延。 (由史蒂文·C·豪威尔评论。)

Disclaimer: Though this book is officially distributed through Real Python, I recommend it independently of my connection with Real Python. I purchased this book when it was first released, before I had the opportunity to write for Real Python. For further evidence of the value of this book, check out the Amazon reviews: 148, averaging 4.8 out of 5 stars, at the time of this review. — Steve

免责声明:尽管这本书是通过Real Python正式发行的,但我建议与我与Real Python的联系无关地进行推荐。 在有机会为Real Python编写代码之前,我是在本书首次发行时购买的。 有关本书价值的更多证据,请在撰写本文时查看亚马逊评论 :148 ,平均5星中有4.8条。 —史蒂夫

流利的Python:清晰,简洁,有效的编程 (Fluent Python: Clear, Concise, and Effective Programming)

Luciano Ramalho (O’Reilly, 2014)

卢西亚诺·拉玛略(Luciano Ramalho)(奥莱利,2014)

"Fluent Python" Book Cover

This book was written for experienced Python 2 programmers who want to become proficient in Python 3. Consequently, this book is perfect for someone with a solid foundation in the basics of Python, 2 or 3, who wants to take their skills to the next level. Additionally, this book also works well as a reference for an experienced programmer from another language who wants to look up “How do I do <x> in Python?”

这本书是为想要熟练掌握Python 3的经验丰富的Python 2程序员而写的。因此,这本书对于那些希望将自己的技能提升到更高水平的具有Python 2或3基础知识的人来说非常适合。 。 此外,这本书还可以作为其他语言的经验丰富的程序员的参考书,该程序员希望查找“如何在Python中执行<x> ”?

The book is organized by topic so that each section can be read independently. While many of the topics covered in this book are found in introductory books, Fluent Python provides much more detail, illuminating many of the more nuanced and overlooked features of the Python language.

本书按主题进行组织,因此每个部分都可以独立阅读。 尽管本书介绍的许多主题都在入门书籍中找到,但Fluent Python提供了更多细节,阐明了Python语言许多细微差别和被忽视的功能。

The chapters are broken into the following six sections:


  1. Prologue: introduces Python’s object-oriented nature and the special methods that keep Python libraries consistent
  2. Data Structures: covers sequences, mappings, sets, and the difference between str and bytes
  3. Functions as Objects: explains the consequences of functions being first-class objects in the Python language
  4. Object-Oriented Idioms: includes references, mutability, instances, multiple inheritance, and operator overloading
  5. Control Flow: extends beyond the basic conditionals and covers the concept of generators, context managers, coroutines, yield from syntax, and concurrency using asyncio
  6. Metaprogramming: explores the lesser know aspects of classes, discussing dynamic attributes and properties, attribute descriptors, class decorators, and metaclasses
  1. 序言 :介绍Python的面向对象性质以及使Python库保持一致的特殊方法
  2. 数据结构 :涵盖序列,映射,集合以及strbytes之间的差异
  3. 作为对象的函数:解释函数成为Python语言中一流对象的后果
  4. 面向对象的成语 :包括引用,可变性,实例,多重继承和运算符重载
  5. 控制流 :扩展了基本条件,并涵盖了生成器,上下文管理器,协程,语法yield from以及使用asyncio并发性的asyncio
  6. 元编程 :探讨类的鲜为人知的方面,讨论动态属性和属性,属性描述符,类装饰器和元类

With code examples on almost every page, and numbered call-outs linking lines of code to helpful descriptions, this book is extremely approachable. Additionally, the code examples are geared toward the interactive Python console, a practical approach to exploring and learning the concepts presented.

几乎每个页面上都有代码示例,并且编号的标注将代码行链接到有用的描述,这本书非常容易上手。 此外,这些代码示例还面向交互式Python控制台,这是一种探索和学习所介绍概念的实用方法。

I find myself turning to this book when I have a Python question and want an explanation that is more thorough than the one I would likely get on Stack Overflow. I also enjoy reading this book when I have a bit of down-time and just want to learn something new. On more than one occasion, I have found that a concept I recently learned from this book unexpectedly turned out to be the perfect solution to a problem I had to solve. (Reviewed by Steven C. Howell.)

当我遇到Python问题并想要比在Stack Overflow上得到的解释更全面的解释时,我会转向本书。 当我有一些停机时间并且只想学习新知识时,我也喜欢阅读本书。 我不止一次地发现,最近从本书中学到的一个概念出乎意料地成为了我必须解决的问题的完美解决方案。 (由史蒂文·C·豪威尔评论。)

有效的Python:编写更好的Python的59种方法 (Effective Python: 59 Ways to Write Better Python)

Brett Slatkin (Addison-Wesley, 2015)

布雷特·斯拉特金(Brett Slatkin)(Addison-Wesley,2015)

"Effective Python: 59 Ways to Write Better Python" Book Cover

This book is a collection of 59 independent articles that build on a basic understanding of Python to teach Pythonic best practices, lesser known functionality, and built-in tools. The topics range in complexity, beginning with the simple concept of being aware of which Python version you’re using, and ending with the more complicated, and typically ignored, concept of identifying memory leaks.

这本书是59篇独立文章的集合,这些文章建立在对Python的基本理解之上,以教授Python的最佳实践,鲜为人知的功能和内置工具。 主题的复杂程度各不相同,首先是一个简单的概念,即了解所使用的Python版本,最后是更复杂(通常被忽略)的识别内存泄漏的概念。

Each article is a combination of example code, discussion, and a list of things to remember.


As each article is independent, this is a great book to jump around in, allowing you to focus on the topics that are most applicable or interesting. This also makes it perfect for reading one article at a time. With each article being around two to four pages in length, you could make time to read one article per day, finishing the book in two to three months (depending on whether you read on weekends).

由于每篇文章都是独立的,因此这是一本很棒的书,可以让您专注于最适用或最有趣的主题。 这也使其非常适合一次阅读一篇文章。 每篇文章的长度约为两到四页,您可以抽出时间每天阅读一篇文章,并在两到三个月内完成这本书(取决于您是否在周末阅读)。

The articles are grouped into the following 8 chapters:


  1. Pythonic Thinking: introduces the best ways to perform common tasks, while taking advantage of how Python is implemented
  2. Functions: clarifies nuanced differences of Python functions and outlines how to use functions to clarify intention, promote reuse, and reduce bugs
  3. Classes and Inheritance: outlines the best practices when working with Python classes
  4. Metaclasses and Attributes: illuminates the somewhat mysterious topic of metaclasses, teaching you how to use them to create intuitive functionality
  5. Concurrency and Parallelism: explains how to know to write multi-threaded applications in Python
  6. Built-in Modules: introduces a few of Python’s lesser-known built-in libraries to make your code more useful and reliable
  7. Collaboration: discusses proper documentation, packaging, dependency, and virtual environments
  8. Production: covers the topics of debugging, optimization, testing, and memory management
  1. Pythonic思考 :介绍执行常见任务的最佳方法,同时利用Python的实现方式
  2. 函数 :阐明Python函数的细微差别,并概述如何使用函数阐明意图,促进重用和减少错误
  3. 类和继承 :概述使用Python类时的最佳实践
  4. 元类和属性 :阐明元类的神秘话题,教您如何使用它们创建直观的功能
  5. 并发和并行 :解释如何知道如何用Python编写多线程应用程序
  6. 内置模块 :引入了一些Python鲜为人知的内置库,使您的代码更有用和更可靠
  7. 协作 :讨论适当的文档,打包,依赖项和虚拟环境
  8. 生产 :涵盖调试,优化,测试和内存管理的主题

If you have a solid foundation in Python and want to fill in holes, deepen you understanding, and learn some of the less obvious features of Python, this would be a great book for you. (Reviewed by Steven C. Howell.)

如果您在Python方面有扎实的基础,并且想填补漏洞,加深了解并学习Python的一些不太明显的功能,那么这对您来说将是一本不错的书。 (由史蒂文·C·豪威尔评论。)

Python食谱 (Python Cookbook)

David Beazley & Brian K. Jones (O’Reilly, 3rd edition, 2013)

David Beazley和Brian K.Jones(O'Reilly,2013年第3版)

Python Cookbook, 3rd. Edition

What makes this book stand out is its level of detail. Code cookbooks are typically designed as short and sweet manuals to illustrate slick ways of doing everyday tasks. In this case, each recipe in Python Cookbook has an extended code solution as well as an author’s discussion of some particular elements of the solution.

使本书脱颖而出的是其详细程度。 代码手册通常被设计成简短易懂的手册,以说明完成日常任务的巧妙方式。 在这种情况下,Python Cookbook中的每个配方都有扩展的代码解决方案,以及作者对解决方案某些特定元素的讨论。

Each recipe starts out with a clear problem statement, such as, “You want to write a decorator that adds an extra argument to the calling signature of the wrapped function.” It then jumps into a solution that uses modern, idiomatic Python 3 code, patterns, and data structures, often spending four to five pages discussing the solution.

每个配方都以清晰的问题陈述开头,例如,“您想编写一个装饰器,为包装函数的调用签名添加一个额外的参数。” 然后跳入使用现代惯用的Python 3代码,模式和数据结构的解决方案,通常花四到五页讨论该解决方案。

Based on its more involved and sophisticated examples, and the authors’ own recommendation in the preface, this is probably the most advanced Python book on our list. Despite that, don’t be scared away if you consider yourself an intermediate Python programmer. Who’s judging, anyway? There’s an old saying that goes something like this:

根据其涉及更多和更复杂的示例,以及作者在序言中的推荐,这可能是我们列表中最高级的Python书籍。 尽管如此,如果您认为自己是中级Python程序员,请不要害怕。 谁来评判? 有句老话说:

“The best way to become a better basketball player is to lose to the best players you can find, rather than beating the worst.”


You may see some code blocks you don’t fully understand—come back to them in a few months. Re-read those sections after you’ve picked up a few additional concepts, and suddenly, it will click. Most of the chapters start out fairly straightforward, and then gradually become more intense.

您可能会看到一些您不完全理解的代码块,请在几个月后再回来看看。 在学习了一些其他概念之后,请重新阅读这些部分,然后突然单击。 大多数章节以相当简单的方式开始,然后逐渐变得更加激烈。

The latter half of the book illustrates designs like decorator patterns, closures, accessor functions, and callback functions.


It’s always nice to read from a trustworthy source, and this book’s authors certainly fit that bill. David Beazley is a frequent keynote speaker at events such as PyCon and also the author of Python Essential Reference. Similarly, Brian K. Jones is a CTO, the creator of a Python magazine, and founder of the Python User Group in Princeton (PUG-IP).

从值得信赖的消息源中阅读总是很高兴,而且本书的作者当然也很满意。 David Beazley经常在诸如PyCon之类的活动上做主旨演讲,同时还是Python Essential Reference的作者。 同样,Brian K. Jones是CTO,Python杂志的创建者,也是普林斯顿Python用户组(PUG-IP)的创始人。

This particular edition is written and tested with Python 3.3. (Reviewed by Brad Solomon.)

该特定版本是使用Python 3.3编写和测试的。 (由Brad Solomon审查。)

获取编码! (Get Coding!)

One of the awesome things about Python is it has a relatively low barrier to entry, compared to many other languages. Despite this, learning Python is a never-ending process. The language is relevant for such a wide variety of tasks, and evolves so much that there will always be something new to discover and learn. While you can pick up enough Python to do some fun things in a week or two, people who’ve been using Python for twenty years will tell you they’re still learning new things they can do with this flexible and evolving language.

与许多其他语言相比,Python的令人敬畏的事情之一是它的进入门槛相对较低。 尽管如此,学习Python是一个永无止境的过程。 该语言与各种各样的任务相关,并且发展得如此之多,以至总会有新的发现和学习的东西。 尽管您可以使用足够的Python在一两周内完成一些有趣的事情,但使用Python已有20年的人会告诉您,他们仍在学习使用这种灵活且不断发展的语言可以做的新事情。

To ultimately be successful as a Python programmer, you need to begin with a solid foundation, then gain a deeper understanding of how the language works, and how to best put it to use. To gain a solid foundation, you really can’t go wrong with any of the best books to learn Python. If you want to learn Python with a child, or maybe teach a group of kids, check out the list of best Python books for kids. After you’ve got your feet wet, check out some of the best intermediate and advanced Python books to dig in deeper to less obvious concepts that will improve the efficiency of your code.

为了最终获得成功,成为Python程序员,您需要从坚实的基础开始,然后对语言的工作方式以及如何最好地使用它有更深入的了解。 为了打下坚实的基础,您确实不会错于任何学习Python最佳书籍 。 如果您想与孩子一起学习Python,或者可能要教一组孩子,请查看针对孩子的最佳Python书籍清单 。 弄湿了您的脚后,请阅读一些最佳的中级和高级Python书籍 ,以深入了解不那么明显的概念,这些概念将提高代码的效率。

All of these books will teach you what you need to know to legitimately call yourself a Python coder. The only ingredient missing is you.

所有这些书都将教您合法地称为Python编码器所需的知识。 唯一缺少的成分是您。

翻译自: https://www.pybloggers.com/2018/09/the-best-python-books/


  • 0
  • 0
  • 1
  • 一键三连
  • 扫一扫,分享海报

评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
钱包余额 0