python的全局变量 local variable ‘xxx‘ referenced before assignment

    技术2022-07-10  128

    在python中一个方法中更改全局变量出错 解决方法:在这个方法体中给全局变量前加global

    errorTimes=0 def f(): global errorTimes errorTimes+=1 print(errorTimes)
    Processed: 0.013, SQL: 9