本来是instance. methodname=types.MethodType(methodName,instance)我改成 methodname=types.MethodType(methodName,instance),即把开头的instance. 去掉,不也能实现一样的功能吗,开头的instance.是不是多余了啊,因为本来就是就是给参数2的instance绑定方法的,写两遍instance有意义吗
1 回答

慕少森
TA贡献2019条经验 获得超9个赞
在Python中,对这两个东西有明确的规定:
函数function —— A series of statements which returns some value to a caller. It can also be passed zero or more arguments which may be used in the execution of the body.
方法method —— A function which is defined inside a class body. If called as an attribute of an instance of that class, the method will get the instance object as its first argument (which is usually called self).
从定义的角度上看,我们知道函数(function)就相当于一个数学公式,它理论上不与其它东西关系,它只需要相关的参数就可以。所以普通的在module中定义的称谓函数是很有道理的。
那么方法的意思就很明确了,它是与某个对象相互关联的,也就是说它的实现与某个对象有关联关系。这就是方法。虽然它的定义方式和函数是一样的。也就是说,在Class定义的函数就是方法。
添加回答
举报
0/150
提交
取消