Python Basics Python 基础

1.1.1: Python Basics Python 基础

Python是一种解释语言。
Python is an interpreted language.
这意味着您可以运行Python程序,而无需首先链接或编译它们。
That means you can run your Python programs without the need to first link or compile them.
Python有两种不同的模式。
Python has two different modes.
这些模式称为交互模式和标准模式。
These modes are called the interactive mode and the standard mode.
交互模式用于一次试验一行代码或一个表达式。
The interactive mode is meant for experimenting your code one line or one expression at a time.
相比之下,标准模式非常适合从头到尾运行程序。
In contrast, the standard mode is ideal for running your programs from start to finish.
我自己经常在这两种Python模式之间切换。
Myself, I often alternate between these two Python modes.
如果手头的任务相对简单,我倾向于直接以标准模式编写代码。
If the task at hand is relatively easy, I tend to write the code directly in the standard mode.
但是,如果代码对我来说更具挑战性,我倾向于在交互模式下花费更多的时间。
However, if the code is more challenging to me,I tend to spend more time in the interactive mode.
这样,我可以在将每一行导入标准模式之前完善每一行。
That way I can perfect every line before I import that to the standard mode.
Python程序往往比C或C++或java中的等效程序短得多。
Python programs tend to be much shorter than equivalent programs in C or C++ or Java.
这是因为Python是一种高级语言。
This is because Python is a high-level language.
它的数据类型允许您以非常简洁的方式表达复杂的操作。
It has data types that allow you to express complex operations in a very concise manner.
最后,您应该知道Python是如何命名的。
Finally, you should know how Python gets its name.
Python并不像你想象的那样以蛇命名。
Python is not named after the snake, as you might have imagined.
事实上,Python的名字来源于《英国广播公司》MythyPython的飞行马戏团,这是我极力推荐的一个节目。
In fact, Python is named after the inimitable BBC show Monty Python’s Flying Circus, a show that I highly recommend.
除了使用核心Python之外,我们还将使用几个Python包来执行科学计算。
In addition to using just core Python, we’ll be using several Python packages to perform scientific computations.
但是,我们将使用Python发行版,而不是一次手动安装200多个包。
But instead of installing more than 200 packages manually one at a time, we will be using a Python distribution.
发行版由核心Python包和数百个模块组成,所有模块都可以无缝地协同工作。
A distribution consists of the core Python package and several hundred modules, all working seamlessly together.
所有这些都可以通过一次下载获得。
All of this is available through a single download.
目前有几种Python发行版可用。
There are currently several Python distributions available.
我们将在本课程中使用的是Anaconda Python发行版。
The one we will be using in this course is called the Anaconda Python distribution.
在录制时,此重新分发支持近300个包,并且几乎每天都会添加新包。
At the time of recording, this redistribution supports almost 300 packages and new packages are added almost daily.
此外,Anaconda还包括两个非常有用的开发环境,分别称为Jupyter和Spyder。
In addition, Anaconda also includes two very useful development environments,which are called Jupyter and Spyder.
本课程将广泛使用这两种环境。
This course will be making extensive use of both of these environments.
经常会出现以下问题:
Questions often come up:
我应该学习Python 2还是Python 3?
Should I learn Python 2 or Python 3?
事实是,有些人更喜欢Python 2,有些人更喜欢Python 3。
And the truth of the matter is, some people like Python 2 better, some people like Python 3 better.
了解更多关于Python 2和Python 3问题的有用地方是Python.org。
A useful place for learning more about the Python 2 versus Python 3 issue is python.org.
该网站提供了一份特别简明的情况摘要。
That website provides an especially concise summary of the situation.
根据该网站,Python2是传统的,而Python3是该语言的现在和未来。
According to the website, Python 2 is legacy,whereas Python 3 is the present and future of the language.
事实上,Python3已经存在好几年了。
Python 3 has, in fact, been around for already several years.
Python 3.0于2008年发布。
Python 3.0 was released in 2008.
那么Python3有什么缺点吗?
So are there any downsides to Python 3?
实际上,只有一个主要的缺点,那就是Python3与Python2不向后兼容。
Well, there is really only one principal downside which is that Python 3 is not backwards compatible with Python 2.
这意味着,如果您用Python3编写代码,运行Python2的人将无法运行该代码。
What that means, if you write your code in Python 3, somebody running Python 2 will not be able to run that code.
这就是我们在本课程中使用Python 3的原因。
Here is why we will be using Python 3 in this course.
所有新的标准库改进只在Python3中默认可用。
All new standard library improvements will only be available by default in Python 3.
Python3对于新手来说也更容易学习,核心语言的几个方面是
Python 3 is also easier for newcomers to learn,and several aspects of the core language are
比Python2中的更加一致。
more consistent than those in Python 2.
Python3还消除了许多容易让刚开始学习Python的程序员绊倒的怪癖。
Python 3 also eliminates many of the quirks that can easily trip up beginning programmers learning Python.
因此,现在是学习Python 3的好时机。
So this is a good time to be learning Python 3.
许多核心Python开发人员认为,Python 3显然是新项目学习的首选,
Many of the core Python developers believe that Python 3 became the obvious choice to learn for new projects,
从2015年9月开始。
starting in September 2015.
建议人们学习Python 3,除非他们有很好的理由学习Python 2。
The recommendation is that people learn Python 3 unless they have a very good reason to be learning Python 2.
所以,除非你有非常特殊的理由学习Python 2,否则我想邀请你和我一起学习Python 3。
So unless you have a very special reason to learn Python 2,I would like to invite you to learn Python 3 with me.


  目录