Python的UnboundLocalError: local variable 'xxx' referenced before assignment

咱们编写Python的时候,有时会遇到这种状况:明明在函数外部已经定义了变量n,在函数内部先把该值打印出来,而后再使该变量自增,运行时却遇到了这样的错误:python UnboundLocalError: local variable 'xxx' referenced before assignment 函数 以下代码片所示:code n=0 def func(): print n n+=1
相关文章
相关标签/搜索