Python编程语言随着人工智能的春风越来越受欢迎。我们的团队也一直在思考如何向没有多少计算机基础的人推广Python的问题。本人最近看了一本书叫“Think Python - How to Think Like a Computer Scientist” -- 中文版叫“像计算机科学家一样思考Python”。这本书是面向Python初学者的。首先介绍的是一些编程的基本内容,给出概念和解释,然后循序渐进地深入讲解每个概念。复杂的部分,比如递归以及面向对象编程,都分成一个个小块,以多个章节的方式来逐步介绍。

书写得非常好,对于Python和编程的解释既准确又容易明白,非常适合入门者。同时作者功力深厚,真正对于计算机科学有着深刻的理解。本人从中学开始学Basic语言,出来工作后也有十多年软件领域经验,读此书过程中依然不断有拍案叫绝的感受,看完对于很多概念都有了进一步的领悟。全力推荐!

此书适合中学以上文化的读者。初中及以下的学生,建议先通过学习Scratch之类的图形化编程工具入门,对编程的概念有基本了解,再接触Python等直接编码语言。

下面这个链接里有英文版的PDF可免费下载:

http://greenteapress.com/thinkpython2/thinkpython2.pdf

亚马逊上面有中文版可购买:

https://www.amazon.cn/dp/B01ION3W54/ref=sr_1_1?ie=UTF8&qid=1525683507&sr=8-1&keywords=%E6%80%9D%E8%80%83python

本人读的是英文版。下面尝试翻译第一章介绍什么是编程的内容给大家感受一下:

编程之路

本书的目的是教你学会像计算机科学家一样来思考。这种思考方式集合了数学、工程和自然科学的一些精华。计算机科学家像数学家一样使用规范的语言来阐述思想(特别是涉及计算的部分);像工程师一样设计物品、组装系统,并且在不同的方案中寻找最优解;像自然科学家一样观察复杂系统的行为,建立猜想,总结规律,并用规律来预测未来、检验规律。

计算机科学家最重要的技能就是解决问题。解决问题意味着有能力确切地阐述问题,创造性地思考解决方法,并且清晰准确地表达出解决方案。而学习编程的过程正是培养这种解决问题能力的一个绝佳机会。这就是为什么本章的标题叫做“编程之路”。

“编程之路”有两个层面的意思:一个层面,你会在学习过程中掌握编程这一有用的技能。另一层面,你会学会如何用编程来到达目标。这个(些)目标会随着学习的深入而逐渐清晰。(如:用Python实现人工智能需求)

程序是什么?

程序是一系列让计算机进行运算的指令序列。这种运算可以是数学上的,如求解一组等式或求多项式的根;也可以是符号运算,比如在文档中搜索和替换文字,或是一些图形化操作,比如处理图像或者播放一段视频。

不同编程语言的具体细节看起来很不一样,但几乎所有编程语言都会有一些基础指令:

- 输入:从键盘、文件、网络或者其他设备上获得数据

- 输出:将数据显示在屏幕中,或者存到文件、通过网络发送等等

- 数学运算:进行基本的数学运算,如加法或者乘法

- 条件执行:检查特定条件是否满足来运行相应的代码

- 重复:重复进行一些操作,通常会有些变化

大家可能不太相信,但编程的核心内容就这么多。你用过的所有程序,无论多么复杂,都是由这样的基础指令组成的。因此大家可以把编程的过程看成是一个把庞大复杂任务分解成细小任务的过程,这个分解过程一直进行到每个小任务都适合使用上述的基础指令来解决为止。

附上英文原文给大家参考:

Chapter 1 The way of the program

The goal of this book is to teach you to think like a computer scientist. This way of thinking combines some of the best features of mathematics, engineering, and natural science. Like mathematicians, computer scientists use formal languages to denote ideas (specifically computations). Like engineers, they design things, assembling components into systems and evaluating tradeoffs among alternatives. Like scientists, they observe the behavior of complex systems, form hypotheses, and test predictions.

The single most important skill for a computer scientist is problem solving. Problem solving means the ability to formulate problems, think creatively about solutions, and express a solution clearly and accurately. As it turns out, the process of learning to program is an excellent opportunity to practice problem-solving skills. That’s why this chapter is called, “The way of the program”.

On one level, you will be learning to program, a useful skill by itself. On another level, you will use programming as a means to an end. As we go along, that end will become clearer.

1.1 What is a program?

A program is a sequence of instructions that specifies how to perform a computation. The computation might be something mathematical, such as solving a system of equations or finding the roots of a polynomial, but it can also be a symbolic computation, such as searching and replacing text in a document or something graphical, like processing an image or playing a video.

The details look different in different languages, but a few basic instructions appear in just about every language:

input: Get data from the keyboard, a file, the network, or some other device.

output: Display data on the screen, save it in a file, send it over the network, etc.

math: Perform basic mathematical operations like addition and multiplication.

conditional execution: Check for certain conditions and run the appropriate code.

repetition: Perform some action repeatedly, usually with some variation.

Believe it or not, that’s pretty much all there is to it. Every program you’ve ever used, no matter how complicated, is made up of instructions that look pretty much like these. So you can think of programming as the process of breaking a large, complex task into smaller and smaller subtasks until the subtasks are simple enough to be performed with one of these basic instructions.