Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

TypeError: printBB() takes 0 positional arguments but

class BB:

def printBB():
    print('no zuo no die')

BB.printBB()
bb=BB()
bb.printBB()
no zuo no die
TypeError: printBB() takes 0 positional arguments but 1 was given

bb.printBB()是这一行报错

class BB():

def printBB(self):
    print('no zuo no die')

BB().printBB()
bb=BB()
bb.printBB()

如果printBB后有self参数 那BB后需要()。相当于调用本身对象
不加self相当于没调用本身对象,所以bb=BB() 旗下没printBB方法?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

class的方法不加self?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...