Skip to content

add zh trans #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions translations/zh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Python 编程思维第三版

> 来源:[`allendowney.github.io/ThinkPython/`](https://allendowney.github.io/ThinkPython/)
>
> 译者:[飞龙](https://github.com/wizardforcel)
>
> 协议:[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)
23 changes: 23 additions & 0 deletions translations/zh/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
+ [Python 编程思维第三版](README.md)
+ [Think Python](tnkpy3e_01.md)
+ [前言](tnkpy3e_02.md)
+ [1\. 编程作为一种思维方式](tnkpy3e_03.md)
+ [2\. 变量与语句](tnkpy3e_04.md)
+ [3. 函数](tnkpy3e_05.md)
+ [4\. 函数与接口](tnkpy3e_06.md)
+ [5. 条件语句与递归](tnkpy3e_07.md)
+ [6. 返回值](tnkpy3e_08.md)
+ [7\. 迭代与搜索](tnkpy3e_09.md)
+ [8\. 字符串和正则表达式](tnkpy3e_10.md)
+ [9\. 列表](tnkpy3e_11.md)
+ [10\. 字典](tnkpy3e_12.md)
+ [11\. 元组](tnkpy3e_13.md)
+ [12\. 文本分析与生成](tnkpy3e_14.md)
+ [13\. 文件与数据库](tnkpy3e_15.md)
+ [14\. 类和函数](tnkpy3e_16.md)
+ [15\. 类与方法](tnkpy3e_17.md)
+ [16\. 类和对象](tnkpy3e_18.md)
+ [17. 继承](tnkpy3e_19.md)
+ [18\. Python 附加功能](tnkpy3e_20.md)
+ [19. 最后的思考](tnkpy3e_21.md)
+ [空白笔记本](tnkpy3e_22.md)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions translations/zh/tnkpy3e_01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Think Python

> 原文:[`allendowney.github.io/ThinkPython/`](https://allendowney.github.io/ThinkPython/)

*Think Python* 是一本为没有编程经验的人(或者曾经尝试过但觉得困难的人)介绍 Python 的书。你可以在 [Bookshop.org](https://bookshop.org/a/98697/9781098155438) 和 [Amazon](https://www.amazon.com/_/dp/1098155432?smid=ATVPDKIKX0DER&_encoding=UTF8&tag=oreilly20-20&_encoding=UTF8&tag=greenteapre01-20&linkCode=ur2&linkId=e2a529f94920295d27ec8a06e757dc7c&camp=1789&creative=9325) 购买第三版的纸质书和电子书。

![`raw.githubusercontent.com/AllenDowney/ThinkPython/v3/think_python_3e.jpg`](https://raw.githubusercontent.com/AllenDowney/ThinkPython/v3/think_python_3e.jpg)

[这是本书在 Green Tea Press 的主页](https://greenteapress.com/wp/think-python-3rd-edition/)。

第三版的主要变化有:

+ 本书现在完全使用 Jupyter 笔记本格式,你可以在同一个地方阅读文本、运行代码并完成练习。通过下面的链接,你可以在 Colab 上运行这些笔记本,所以你无需安装任何东西即可开始。

+ 这本书的内容经过了大量修订,部分章节顺序有所调整。现在有更多的练习,我认为许多练习都更好。

+ 每一章的结尾都有一些建议,推荐使用像 ChatGPT 和 Colab AI 这样的工具来深入学习并帮助完成练习。

## 这些笔记本

**第一章:将编程作为一种思维方式**

+ [点击这里在 Colab 上运行第一章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap01.ipynb)

**第二章:变量与语句**

+ [点击这里在 Colab 上运行第二章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap02.ipynb)

**第三章:函数**

+ [点击这里在 Colab 上运行第三章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap03.ipynb)

**第四章:函数与接口**

+ [点击这里在 Colab 上运行第四章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap04.ipynb)

**第五章:条件语句与递归**

+ [点击这里在 Colab 上运行第五章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap05.ipynb)

**第六章:返回值**

+ [点击这里在 Colab 上运行第六章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap06.ipynb)

**第七章:迭代与搜索**

+ [点击这里在 Colab 上运行第七章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap07.ipynb)

**第八章:字符串与正则表达式**

+ [点击这里在 Colab 上运行第八章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap08.ipynb)

**第九章:列表**

+ [点击这里在 Colab 上运行第九章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap09.ipynb)

**第十章:字典**

+ [点击这里在 Colab 上运行第十章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap10.ipynb)

**第十一章:元组**

+ [点击这里在 Colab 上运行第十一章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap11.ipynb)

**第十二章:文本分析与生成**

+ [点击这里在 Colab 上运行第十二章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap12.ipynb)

**第十三章:文件与数据库**

+ [点击这里在 Colab 上运行第十三章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap13.ipynb)

**第十四章:类与函数**

+ [点击这里在 Colab 上运行第十四章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap14.ipynb)

**第十五章:类与方法**

+ [点击这里在 Colab 上运行第十五章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap15.ipynb)

**第十六章:类与对象**

+ [点击这里在 Colab 上运行第十六章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap16.ipynb)

**第十七章:继承**

+ [点击这里在 Colab 上运行第十七章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap17.ipynb)

**第十八章:Python 扩展**

+ [点击这里在 Colab 上运行第十八章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap18.ipynb)

**第十九章:总结思考**

+ [点击这里在 Colab 上运行第十九章](https://colab.research.google.com/github/AllenDowney/ThinkPython/blob/v3/chapters/chap19.ipynb)

## 教师资源

如果你正在使用这本书进行教学,以下是一些你可能会觉得有用的资源。

+ 你可以从[这个 GitHub 仓库](https://github.com/AllenDowney/ThinkPythonSolutions/tree/v3/soln)下载包含解答的笔记本。

+ 每章的测验和整本书的总结性测验可以根据要求提供。

+ *使用 Jupyter 进行教学与学习* 是一本在线书籍,提供了在课堂上有效使用 Jupyter 的建议。你可以在[这里阅读这本书](https://jupyter4edu.github.io/jupyter-edu-book)。

+ 在课堂上使用笔记本的最佳方式之一是现场编程,教师编写代码,学生在自己的笔记本中跟随。要了解现场编程——以及关于教学编程的其他很多宝贵建议——我推荐由 The Carpentries 提供的教师培训,[你可以在这里阅读](https://carpentries.github.io/instructor-training)。

+ 对于每一章,我创建了一个包含原文的“空白”笔记本,但大部分代码已被删除。这些笔记本对于进行跟随练习非常有用,学习者可以在其中填写空白。[空白笔记本的链接在这里](https://allendowney.github.io/ThinkPython/blank.html)。
119 changes: 119 additions & 0 deletions translations/zh/tnkpy3e_02.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# 前言

> 原文:[`allendowney.github.io/ThinkPython/chap00.html`](https://allendowney.github.io/ThinkPython/chap00.html)

## 这本书适合谁?

如果你想学习编程,你来对地方了。Python 是初学者最好的编程语言之一,它也是目前最具需求的技能之一。

你也来得正是时候,因为现在学习编程可能比以往任何时候都要容易。借助像 ChatGPT 这样的虚拟助手,你不必孤单学习。在本书中,我将建议你如何使用这些工具加速学习。

本书主要面向从未编程过的人和那些有其他编程语言经验的人。如果你已经有了丰富的 Python 经验,可能会觉得前几章的进度太慢。

学习编程的一个挑战是你必须学习*两*种语言:一种是编程语言本身,另一种是我们用来讨论程序的词汇。如果你只学习编程语言,当你需要解释错误信息、阅读文档、与他人交流或者使用虚拟助手时,你很可能会遇到问题。如果你已经做了一些编程,但没有学会这第二种语言,希望你能从本书中受益。

## 本书目标

在写这本书时,我尽力小心处理词汇。当一个术语首次出现时,我会对其进行定义。在每一章的末尾,还有一个术语表,回顾了本章中出现的术语。

我还尽量简明扼要。读书所需的思维努力越少,你就越能集中精力编程。

但是,你不能仅仅通过读书来学习编程——你必须实践。因此,本书在每一章的末尾都包括了练习,帮助你巩固所学内容。

如果你认真阅读并坚持完成练习,你会取得进展。但我要提醒你——学习编程并不容易,即使对于经验丰富的程序员来说,它也可能是令人沮丧的。随着学习的深入,我会建议一些策略,帮助你编写正确的程序并修复错误的程序。

## 导读

本书的每一章都是建立在前一章的基础上的,因此你应该按顺序阅读,并在继续之前花时间完成练习。

前六章介绍了基本的元素,如算术、条件语句和循环。它们还介绍了编程中最重要的概念——函数,以及使用函数的一种强大方法——递归。

第七章和第八章介绍了字符串——它们可以表示字母、单词和句子——以及与之相关的算法。

第 9 到第十二章介绍了 Python 的核心数据结构——列表、字典和元组——这些是编写高效程序的强大工具。第十二章介绍了分析文本和随机生成新文本的算法。像这样的算法是大型语言模型(LLM)的核心,因此本章将让你了解像 ChatGPT 这样的工具是如何工作的。

第十三章讲解了如何将数据存储到长期存储中——文件和数据库。作为练习,你可以编写一个程序,搜索文件系统并查找重复文件。

第 14 到第十七章介绍了面向对象编程(OOP),这是一种组织程序和它们处理的数据的方式。许多 Python 库是以面向对象的风格编写的,因此这些章节将帮助你理解它们的设计——并定义你自己的对象。

本书的目标不是覆盖整个 Python 语言。而是专注于语言的一个子集,这个子集能够以最少的概念提供最大的能力。尽管如此,Python 仍然有许多功能,可以帮助你高效地解决常见问题。第十八章介绍了其中的一些功能。

最后,第十九章分享了我离别时的想法,并给出了继续编程旅程的建议。

## 第三版有什么新内容?

本版中最大的变化是由两项新技术推动的——Jupyter 笔记本和虚拟助手。

本书的每一章都是一个 Jupyter 笔记本,它是一个包含普通文本和代码的文档。对我而言,这使得编写代码、测试代码并保持与文本一致变得更加容易。对你而言,这意味着你可以在一个地方运行代码、修改代码并完成练习。使用笔记本的说明在第一章中。

另一个大变化是,我增加了有关如何使用像 ChatGPT 这样的虚拟助手的建议,并利用它们加速学习。当本书的上一版在 2016 年出版时,这些工具的前身远不如现在有用,而且大多数人对此一无所知。如今,它们已成为软件工程的标准工具,我认为它们将成为学习编程——以及学习其他许多内容——的变革性工具。

书中的其他变化源于我对第二版的遗憾。

第一个遗憾是我没有强调软件测试。这在 2016 年时就已经是一个遗憾的遗漏,但随着虚拟助手的出现,自动化测试变得更加重要。因此,这一版介绍了 Python 最广泛使用的测试工具——`doctest` 和 `unittest`,并包含了几个练习,你可以在其中练习使用这些工具。

我的另一个遗憾是第二版的练习不够均衡——有些比其他的更有趣,而有些则过于难。转向 Jupyter 笔记本帮助我开发并测试了一个更具吸引力和更有效的练习顺序。

在这次修订中,主题的顺序几乎没有变化,但我重新安排了一些章节,并将两个较短的章节合并为一个。此外,我扩展了字符串的内容,加入了正则表达式。

有些章节使用了海龟图形。在之前的版本中,我使用了 Python 的` turtle`模块,但遗憾的是它在 Jupyter 笔记本中无法工作。所以我用一个新的海龟模块替换了它,应该更易于使用。

最后,我重写了大量的文本,澄清了需要澄清的地方,并删减了那些我可以更简洁表达的部分。

我对这个新版本感到非常自豪——希望你会喜欢!

## 入门指南

对于大多数编程语言,包括 Python,你可以使用许多工具来编写和运行程序。这些工具被称为集成开发环境(IDEs)。一般来说,IDE 有两种类型:

+ 一些 IDE 与包含代码的文件一起工作,因此它们提供了编辑和运行这些文件的工具。

+ 其他 IDE 主要与笔记本一起使用,笔记本是包含文本和代码的文档。

对于初学者,我推荐从像 Jupyter 这样的笔记本开发环境开始。

本书的笔记本可以从[`allendowney.github.io/ThinkPython`](https://allendowney.github.io/ThinkPython)上的在线仓库获得。

有两种使用方式:

+ 你可以下载笔记本并在自己的计算机上运行。在这种情况下,你需要安装 Python 和 Jupyter,这并不难,但如果你想学习 Python,花费大量时间安装软件可能会让人感到沮丧。

+ 另一种选择是通过 Colab 运行笔记本,Colab 是一个在网页浏览器中运行的 Jupyter 环境,因此你无需安装任何东西。Colab 由 Google 运营,且免费使用。

如果你刚开始学习,我强烈建议你从 Colab 开始。

## 教师资源

如果你是用本书进行教学,以下是一些你可能会觉得有用的资源。

+ 你可以在[`allendowney.github.io/ThinkPython`](https://allendowney.github.io/ThinkPython)找到带有习题解答的笔记本,并附有以下额外资源的链接。

+ 每章的测验和整本书的总结性测验可以根据请求提供。

+ *Jupyter 的教学与学习*是一本在线书籍,提供了在课堂上有效使用 Jupyter 的建议。你可以在[`jupyter4edu.github.io/jupyter-edu-book`](https://jupyter4edu.github.io/jupyter-edu-book)阅读这本书。

+ 使用笔记本的最佳方式之一是现场编码,教师编写代码,学生在自己的笔记本中跟随。要了解现场编码并获取关于编程教学的其他建议,我推荐 The Carpentries 提供的讲师培训,网址是[`carpentries.github.io/instructor-training`](https://carpentries.github.io/instructor-training)

## 致谢

非常感谢 Jeff Elkner,他将我的 Java 书籍翻译成 Python,从而启动了这个项目,并让我接触到了最终成为我最喜爱的语言。同时感谢 Chris Meyers,他为 *如何像计算机科学家一样思考* 贡献了几个章节。

感谢自由软件基金会开发的 GNU 自由文档许可证,使我能够与 Jeff 和 Chris 合作,也感谢创用 CC 为我目前使用的许可证提供支持。

感谢 Python 语言的开发者和维护者,以及我使用的库,包括 Turtle 图形模块;感谢我开发本书时使用的工具,包括 Jupyter 和 JupyterBook;还要感谢我使用的服务,包括 ChatGPT、Copilot、Colab 和 GitHub。

感谢 Lulu 的编辑,他们参与了 *如何像计算机科学家一样思考* 的编辑工作,感谢 O'Reilly Media 的编辑,他们参与了 *Think Python* 的编辑工作。

特别感谢第二版的技术审阅者 Melissa Lewis 和 Luciano Ramalho,以及第三版的 Sam Lau 和 Luciano Ramalho(再次感谢!)。我还特别感谢 Luciano 开发了我在多个章节中使用的 Turtle 图形模块,名为 `jupyturtle`。

感谢所有曾与本书早期版本合作的学生,以及所有提交了修正和建议的贡献者。在过去的几年里,超过 100 位眼光敏锐、思考周到的读者提供了建议和修正。他们的贡献和对本项目的热情给予了我极大的帮助。

如果你有任何建议或修正,请发送电子邮件至 `feedback@thinkpython.com`。如果你能至少提供出现错误的句子的一部分,这将帮助我更容易地找到问题。页面和章节号也可以,但不如句子直接有用。谢谢!

[Think Python: 第 3 版](https://allendowney.github.io/ThinkPython/index.html)

版权所有 2024 [Allen B. Downey](https://allendowney.com)

代码许可:[MIT 许可证](https://mit-license.org/)

文本许可:[创用 CC 姓名标示-非商业性使用-相同方式共享 4.0 国际版](https://creativecommons.org/licenses/by-nc-sa/4.0/)
Loading