我是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()`一个参数,而实际上我并没有?我做错了什么?