python新手问题
简明PYTHON教程中有这样一个例子:
class Person: def sayHi(self): print 'hello,how are you?' p=Person() p.sayHi()
Traceback (most recent call last): File "<pyshell#30>", line 1, in <module> class Person: File "<pyshell#30>", line 4, in Person p=Person()
class Person: def sayHi(self): print 'hello,how are you?'#如果你是在python的交互解释器中黏贴代码,请务必在class和后继代码中留空行。p=Person()p.sayHi()
[解决办法]
你这样写是不对的
试试这么写:
class Person: def sayHi(self): print 'hello,how are you?'#如果你是在python的交互解释器中黏贴代码,请务必在class和后继代码中留空行。if "__main__" == __name__: p=Person() p.sayHi()
[解决办法]
class Person: def sayHi(self): print 'hello,how are you?'然后再回车,输入下边的内容p=Person()p.sayHi()
[解决办法]
每一级缩进代表一个作用域,你仔细对比上下两个缩进看是否配对