When I call this class definition, it calls init, init and I give it an x and a y value.
我说过,当我们,调用这个类的定义的时候,它会去调用。
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.
就是给我一个所有东西的列表:,所有的方法,与这个类关联的,有一些是我写的:,还有这里,请注意,是一些内部的定义。
And that first one is init this kind of interesting thing, it's two underbars, init, and two underbars. Underscores, I guess is the right way to say it, not underbars.
然后第一行代码是很有趣的东西,这是两个下划线,然后再有两个下划线,下面的划线,我认为应该这么说,而不是下划线。
And what is it going to happen is that init is going to then apply.
它会被应用于这些参数,那么让我来给大家看个例子吧。
So in fact what happens inside of an object-oriented system, and particularly in init Python's object-oriented system, is the following.
面向对象系统的内部,尤其是在Python的面向,对象系统的内部的过程,就是如下的,当我们调用,它会去创建一个实例。
When I call the class definition, that is I call c point, I'm going to call it with a specific set of arguments.
来创建实例的时候,也就是调用c,point的时候,我会以一个特定的参数集来调用它,然后将要发生的就是init将会被应用。
So, I've got an init in both cases.
好,那么我然后要在这个小小的。
init Init creates a pointer to the instance.
然后这个方法调用了。
I don't have to put an init in, but it's again, usually a good idea to put that in originally.
类定义内做些什么其他的东西呢?,好,在两个例子里,我都有init声明。
Notice that that typically also defines for me what the internal variables are, what the internal characteristics of the class are going to be.
就放进去是比较好的,我写下了init声明意思就是,当你创建一个实例的时候,这就是你要进行的操作。
When we call init, it's going to create the instance, all right, just as we said before.
好,正如我们前面所受的,但是尤其是,它会去用self来引用这个实例。
So another way saying it again is, when I call the class definition, by default I'm going to look to see is there an init method there, and if there is, I'm going to use it.
当我调用类的定义,默认的是语言要去查看,是不是有个init的方法,如果有的话,程序就会调用它,按照惯例。
I've got and init that says, when you create an instance, here's what you do.
我并不需要一定要有init声明,但是这是,再说一次,通常来说把init声明一开始。
How many arguments does init take? Three.
我给了它的参数是一个x值。
I have init.
这就是init方法。
应用推荐