Don't understand why UnboundLocalError occurs (closure) [duplicate]

问题:

This question already has answers here : 这个问题在这里已经有了答案
Closed 4 years ago . 4年前关闭。

What am I doing wrong here?我在这里做错了什么?

counter = 0

def increment():
  counter += 1

increment()

The above code throws an UnboundLocalError .上面的代码抛出一个UnboundLocalError


解决方案:

参考一: https://en.stackoom.com/question/csBf
参考二: https://stackoom.com/question/csBf
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章