Python 问题求解?

>>> class A:
def a(self):
print("I'm a")

>>> A.a()

Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
A.a()
TypeError: unbound method a() must be called with A instance as first argument (got nothing instead)
小弟新手,请轻拍!

手掌心
浏览 518回答 2
2回答

MMTTMM

方法a要通过一实例来调用,如:class A:def a(self):print("I'm a")obj = A()obj.a()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python