- 论坛徽章:
- 0
|
大牛好,
我正在阅读一本关于Python语言的文档,由于本人没有深入学习过Python,但有一定的C语言基础。
我在阅读Class instances章节时,
A class instance is created by calling a class object (see above). A class instance has a namespace implemented as a dictionary which is the first place in which attribute references are searched. When an attribute is not found there, and the instance’s class has an attribute by that name, the search continues with the class attributes. If a class attribute is found that is a user-defined function object, it is transformed into an instance method object whose __self__ attribute is the instance.
这个概念是不是可以理解为:
当一个类方法通过一个实例对象被调用时,__self__代表实例对象本身。
如果是这样理解,是不是说,在编写这样的函数时,应实现__self__参数的身份判断,以区分是类调用的,还是实例调用的? |
|