双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

菜鸟求助

wohu007 wohu007 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
刚看到一篇博客中关于类和对象的讲解,就敲了以下代码,请问下为什么是全局变量没有定义?Python 中不是不用声明变量吗?这是为什么
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
...全文
评论 3
收藏 已收藏
分享
返回顶部
wohu007
脚本语言 37,738 成员 34,208 内容