菜鸟求助
刚看到一篇博客中关于类和对象的讲解,就敲了以下代码,请问下为什么是全局变量没有定义?Python 中不是不用声明变量吗?这是为什么
错误提示:
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
print 'affter move:', summer.method(5,8)
File "<pyshell#23>", line 8, in method
return positon
NameError: global name 'positon' is not defined
class Bird(object):
have_feature = True
way_of_reproduction = 'egg'
def method(self,dx,dy):
position = [0,0]
position[0] = position[0] + dx
position[1] = position[1] + dy
return positon
summer = Bird()
print 'affter move:', summer.method(5,8)
错误提示:
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
print 'affter move:', summer.method(5,8)
File "<pyshell#23>", line 8, in method
return positon
NameError: global name 'positon' is not defined
...全文



