I'd really like to have that modularity that says, I'm only going to get access to the values, not by calling their names, but by calling some specific method to get access to their names.
这样我们就丢掉了代码的模块化,我很希望代码有这样的模块化:,我访问变量的值,不是通过直接调用它们的名字,而是通过调用某个可以,访问这些变量名的方法来访问。
Here's the way I would call it.
下面是我调用它的方法。
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.
我们开始建立类了,我们得到了这些方法,因此实际上你可以说,我怎么知道,哪些方法是关联与这些类的?,为了解决这个问题,我们可以调用,这个方法的作用。
Notice in the class definition here, is there, this is the first thing that's got called, and I just called with the value for x and the value for y, and it went off and did something for me.
就在这里,这是第一个被调用的东西,我用x的值和y的值调用了它,然后这个方法继续进行,并为了做了一些操作。
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的方法,如果有的话,程序就会调用它,按照惯例。
It's still calling cmp, but it's knowing that cmp is just reversing the order of the arguments.
下一次我会带上正确的眼镜的,这还是会去调用cmp方法的,但是我们知道。
应用推荐