When I call this class definition, it calls init, init and I give it an x and a y value.
我说过,当我们,调用这个类的定义的时候,它会去调用。
It's got this funky looking form, right, it says, I've got something that I'm going to call a class, got that key word class right here.
以及我们怎么来使用这些方法,因此我要回到类这个概念上来,让我们来建立第一个类吧,就在你们课堂手册的这儿,我会去定义一个类。
I'll show how that works in just a moment, but estrogen for example, is one of those.
我马上就给你们讲这个过程,举这类分子中的一种,雌激素作为例子
If you look at what the law says, they tend to use the word depository institution.
如果你看法律类文章的话,他们更倾向于储蓄机构这个词。
They can be on store shelves for a long period of time, and that has to do with the economics of food, especially food available to the poor, which we'll discuss later.
因此可以在商品货架上销售很长一段时间,这也与食物的经济学价值有关,特别这类食物穷人也买得起,这个我们以后会讨论
But the fact that this type of report the goverment published itself suggest that they are thinking about it and once it becomes part of the public discourse this typle of issue... some action is likely to follow.
政府自身愿意写出这种报告,从另一角度说明,他们在思考这个问题,一旦这个问题受到公共瞩目,这类问题。,就可能有人开始动手解决。
It's an example of a very common tool that's going to be really useful to us, not just for doing search, but for doing a whole range of problems. That is, in essence, the template the describes a log style algorithm.
不仅仅是做搜索,还可以解决一整类问题,本质上,这个模板就描述了,对数形的算法,我们一会再回来。
PROFESSOR: Last time, Professor Guttag introduced the idea of objects and classes and this wonderful phrase called object-oriented programming.
教授:上节课,Guttag教授,介绍了对象和类的概念以及,面向对象编程这个美妙的短语,这是我今天想继续讲的一个话题。
When I try and evaluate that expression of greater than, is going to go into the class to say greater than is a comp method.
这个大于的操作符的时候,是到类的定义里去识别,大于是一个比较的方法,那么让我在这里说仔细一点吧。
Some of which I built: cmp, init, str. And there, notice, are the internal definitions And in fact I should've said, we often call those things fields.
就是给我一个所有东西的列表:,所有的方法,与这个类关联的,有一些是我写的:,还有这里,请注意,是一些内部的定义。
So now let's look at it.
所以现在让我们来看到这个类。
I'm going to add to it in a second, but I want to build up to this.
关键词“类“在这里,然后我要命名这个类。
OK, the reason I'm saying this is, we have one class definition, is a cookie cutter, it's a template that's going to let us build versions of these things.
同一实例,好,我为什么要说这个的原因是,我们学习了类的定义了,这就像曲奇成型刀一样,它是个让我们建立不同版本的,这些东西的一个模板。
If I want to get out right now the versions of these things, I can ask what's the value of c p 1 x, and it returns it back out.
你可以在那里看到那些,代表笛卡尔坐标点的东西,如果我想要得到现在,这个类的版本的东西的话。
So when I type, I'm sorry, I shouldn't say type, c point although I would have typed it, p dot x, here's what basically happens.
处于特定点的实例的这个概念,我知道它来自于这个类,这个类,when,I,write,因此当我输入,抱歉,我不该说输入的,当我写,虽然我需要输入它,p,x的时候。
It's actually an object somewhere.
当我调用这个类的定义的时候。
So you can actually say, how do I know which methods are associated with the class? For that, we can call dir. And what it does, is it gives me back a listing of all the things, dir all the methods, that are associated with it.
我们开始建立类了,我们得到了这些方法,因此实际上你可以说,我怎么知道,哪些方法是关联与这些类的?,为了解决这个问题,我们可以调用,这个方法的作用。
Right now it's empty, actually it's not quite empty, it has a pointer back to the class.
当我调用了这个类的,定义声明的时候,它在内存中的特定点。
They are instances of a class, and associated with that class is a set of methods.
它们是同一个类的实例,与这个类相关联的是一个方法集,因此例如,我可以说。
And is able to then say, inside of that class definition, find the value of x.
这个类的定义这里然后取值,也可以这么说,在类的定义的里面。
Generally, you think about the immune system protecting against different classes of pathogens and several classes of pathogens are shown on this table.
大体上,你们会认为免疫系统使,我们免受不同种类病原体的侵害,这个表格里介绍了几类病原体
Ok, and again, I'm going to remind you, the class is this template.
就在这里,我想大家在,你们的课堂手册上看看这个,好,我将会回去重建下这个类。
But now I'm going to change it, so what is that new version of class say.
好,我又要提醒下大家,类是这个模板。
Right there, and I'd like you to ook at that in your handout.
着手做这个理想的类了,我想要讲讲概念。
And then of course, there's the word sugar itself and then things like high fructose corn syrup, so there are a lot of ways that sugar gets put into foods and you wouldn't expect it to be there.
当然,还有糖本身这个词,还有像高果糖玉米糖浆这类东西,所以食品中含有很多形式的糖,而且你不知道它的存在
I going to come back in a second to how it actually does that, but it basically says, get me x value for p 1, get me the x value for p 2, compare them, just as you would normally.
是一个类的实例,我要去取的这个实例,所关联的x值,我稍后会讲讲实际上,这里是怎么实现的,但是基本上它的意思就是,给我p1的x值。
These are instances of a class, and associated with that class are a set of methods things that I can deal with.
但是Python的基本思想是相同的,这是一些一个类的实例,这个类关联了一个方法集,我可以做的一些操作。
I can build class stock, and I can test class stock, before I have a class market.
我可以建立一个stock类,然后在有macket类之前测试这个类。
应用推荐