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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章