“ 不带参数(给定1个)”,但我不给
发布于 2021-01-29 17:17:17
我是Python的新手,并且编写了以下简单脚本:
#!/usr/bin/python3
import sys
class Hello:
def printHello():
print('Hello!')
def main():
helloObject = Hello()
helloObject.printHello() # Here is the error
if __name__ == '__main__':
main()
运行它(./hello.py
)时,出现以下错误消息:
Traceback (most recent call last): File "./hello.py", line 13, in <module> main() File "./hello.py", line 10, in main helloObject.printHello() TypeError: printHello() takes no arguments (1 given)
为什么Python认为我给出printHello()
了论据而我却没有给出?我做错了什么?
关注者
0
被浏览
37
1 个回答