1.文章中第一个例子:
class Thing(object):
def test(hi):
print('hi')
a=Thing()
a.test('hello')
运行后会报错:
TypeError: test() takes 1 positional argument but 2 were given
修改后代码:
class Thing(object):
def test(self,hi):#定义类-函数的时候,必须要传入self参数。self:传入地址
print('hi')
a=Thing()
a.test('hello')
#运行后结果如下:
hi