【发布时间】:2014-12-16 07:59:18
【问题描述】:
在下面的代码中,为什么执行的最后一行会报错? x.bf() 中的点运算符不应该将实例 'x' 传递给函数 bf 吗(就像 x.af() 一样)?
class A:
a = 6
def af (self):
return "Hello-People"
class B:
b = 7
def bf (self):
return "Bye-People"
>>> x = A()
>>> b = B()
>>> x.bf = B.bf
>>> x.bf()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: bf() missing 1 required positional argument: 'self'
【问题讨论】:
标签: class oop instance python-3.4