我弱弱的請教一下前輩
從app1.py看的出來 a 這變數有傳到function中
但為什麼app2.py 中 a=a+1
會顯示referenced before assignment呢?
程式如下
""" app1.py """
a = 1
def prt():
print(a)
prt()
# result:1
"""/app1.py""""
"""" app2.py""""
a = 1
def prt():
a = a + 1
# 新增上面那行
print(a)
prt()
# result: File "app2.py", line 4, in prt
a = a+1 UnboundLocalError:
local variable 'a' referenced before assignment
""" /app2.py"""