The name is based on a funny joke many years ago on a British television show, "Monty Python's Flying Circus."
VOA: special.2010.08.01
And for the next, off and on for the next couple of weeks, we'll be talking about Python and program organization.
接下来大概有几周时间,我们将要讨论Pyton语言和程序结构。
Python You can pick up another language in a week, couple of weeks at most, once you know how to do Python.
只要学会了,你可以在一周之内学会任意一种语言,最多两周。
But there's one thing to think you know, you think of I don't know if you've seen the Monty Python's skit.
但是另外,当您想到,不知道您看没看过Monty,Python的滑稽短剧?
And so, in fact, if I wanted the other version of it, in fact, if I do this right, 23 it's going to give me 23 because it does the multiplication first, if I wanted the other version of it, Python I need to tell it that, by using, excuse me, parentheses.
因此,实际上,如果我想换种做法,实际上,如果我去执行这个表达式,返回值是3,因为乘法会被优先执行,如果我需要换种做法,我需要告诉,用括号来告诉它。
The second thing I want to highlight is, that what's going on, is that Python is doing some type checking.
我想强调的第二件事情是,这里发生的是,是Python做了一些类型检查的工作。
Python So I'm using the Python try except to check whether or not the thing is in the memo or not.
所以我将让,去调用except去判断该物品,是否已经在memo中。
Right now it's got that second key word there called pass, which is just Python's way of saying there's an empty body in here.
现在我在完善它的一个简单部分,但是首先,类是用来干什么的呢?,把类认为是可以创建一个。
It's perfectly legal in Python to type that in and get the value back out.
正如我所说的,我更希望用一个,我刚刚写的访问器。
I don't think either of us are thrilled with the text, it's the best we've probably found for Python, it's OK. If you need it, it's there.
我不认为我们俩对于这个课本很满意,这是我们能找到的,最好的版本了,还不错,如果你需要它,就在网站上。
Strings are captured in Python with an open quote and some sequence of characters followed by a closed quote.
字符串在Python中,是以一个开引号开始,然后后面是一系列的字符,以一个尾引号结束。
Now, to my knowledge, most implementations of Python use this way of storing lists, whereas Lisp and Scheme do not.
这正是我希望的,据我所知,Python,的大多数实现,都是用这种方式来存储数组的,而Lisp和Scheme则不是。
And in particular, there are some key words that Python is going to use that have to be excluded.
尤其是,Python需要用的一些关键词,就被排除在外面了。
So in fact what happens inside of an object-oriented system, and particularly in init Python's object-oriented system, is the following.
面向对象系统的内部,尤其是在Python的面向,对象系统的内部的过程,就是如下的,当我们调用,它会去创建一个实例。
i It takes i, which is in some sense 1 the length of those vectors, minus 1, because of the way Python works.
还有i,某种意义上,是那些向量的长度减,减1由于Python的工作方式。
So in this course, Python the language we're going to use is Python.
所以在这个课堂上,我们要用的语言是。
I should also warn you that this code includes some Python concepts, at least one, that you have not yet seen.
我得事先说明这个代码中,包括了一些你没见过的Python语言的概念,至少一个。
I'm using Python's is comparator to say is it the same thing?
来看看这两个东西是不是同一个,它说不是,但是如果我的意思是?
Unfortunately, Python doesn't do this.
来访问这些变量。
This is a keyword to Python that says, when it reads this in the file, it says, I'm creating a definition.
这是Python语言的关键词,当你在文件中读到这个词的时候,它的意思就是我正在创建一个定义。
Which is, and we're going to do some examples of this, initially we just typed in expressions Python into the interpreter; that is,directly into Python And as I suggested last time, the interpreter is actually a program inside of the machine that is basically following the rules we're describing here to deduce the value and print it up.
也就是,我们将会对这一点讲解一些例子,一开始我们只是简单的把表达式输入,到解释器里面去,也就是直接传给,我上次跟大家讲过,解释器实际上是,机器内置的,按照我们描述的规则,来推算出结果值并把值显示出来的一个东西。
Later in the term, we'll see why we have this syntax and why it wasn't just a totally arbitrary Python brain-dead decision by the designers of Python, and many languages before Python, but in fact is a pretty sensible thing.
这个学期的晚些时候,我们会去学学我们学这些语法的原因,以及这些语法其实并不是,和以前其他语言的设计者,一拍脑子做出的决定,实际上制定这些语法其实是相当明智的。
But underlying Python is the same idea.
对数字进行操作的方法集。
So we've looked at how to solve square root we've, looked at two problems, I've tried to instill in you this sense of paranoia which is so valuable, and now we're going to pull back Python and return to something much simpler than numbers, and that's Python. All right?
我们已经研究了如何去求平方根,研究了两种方法,我一直在尝试着给你们逐渐灌输,要偏执的理念,这样的理念非常有价值,现在我们回过头来去学习一些,比数字更简单的东西,也就是,对不对?数学问题很难?
When I'm talking to the interpreter, when I'm typing things in as I just did, to that Python environment, I'm getting what I'm going to call global bindings.
当我和解释器对话时,我会向我说的一样进行输入,输入到Python语言环境中,我会设置全局变量。
And what you should take away from this course is having learned how to design recipes, how to structure recipes, how to do things in modes in Python.
还有,你应该从这个课堂上拿走的是,学会如何设计菜谱,如何构建菜谱,如何在Python语言的模式中设计东西。
That's the internal representation that python uses for this. If I give it some other character, yeah, it would help if I could type, give it some other character.
为什么输入‘3’返回了其它的东西?,这是python在内部的表示方式,如果我输入其它的字符,是的,如果我能输入,输入其它的字符。
And then Java, C++ , Python of, course.
当然还有Python的出现。
Well, basically because it was a design choice when the creators of Python decided to create the language, they basically said, we're always going to have an explicit pointer to the instance.
好,基本上来说这是因为,这是当Python的创造者,决定创造这门语言的时候,的一个设计决定,他们主要的说了说,我们要有一个明确的,指向实例的指针。
You might say, why? Well it turns out there's some trade-offs to it. It has some advantages in terms of power of storing things, it has some disadvantages, primarily in terms of access time.
那可能是某种意义上的权衡,对存储而言,这有优势,但访问的效率上就变成劣势了,幸运的是,python或者。
应用推荐