我不知道为什么发生UnboundLocalError

时间:2020-07-23 05:19:32

标签: python

count = 0

def test():
    number = 3
    while count < 6:
        count = number + 3

test()

上面的代码生成以下错误。

UnboundLocalError:赋值之前引用了本地变量'count'

count = 0

def test():
    number = 3
    while count < 6:
        print(count)
        break

test()

但是上面的代码运行良好。

两个代码有什么区别?

0 个答案:

没有答案
相关问题