采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
origin = 0
def factory(pos): def go(step): nonlocal pos new_pos = pos + step pos = new_pos return new_pos return go tourist = factory(origin) print(tourist(2))
照抄的代码 运行出错 localhost:sslee garywork$ python page9.py File “page9.py”, line 5 nonlocal pos ^ SyntaxError: invalid syntax
是 return pos。
origin = 0 def factory(pos): def go(step): nonlocal pos new_pos = pos + step pos = new_pos return new_pos return go tourist = factory(origin) print(tourist(2))
python代码用缩紧控制代码执行顺序
你确定是照抄的吗 你好像多返回了一个
登录后可查看更多问答,登录/注册
语法精讲/配套练习+思考题/原生爬虫实战
5.5k 7
2.5k 3
2.1k 4
4.1k 22
2.3k 19