0

there is very simple python code. I think, there is no problem in this code. But, i have got follows like "UnboundLocalError: local variable 'c' referenced before assignment"

here is the code

c=1
def i():
    c=c+1
    print(c)
i()

this error comes from line number 3. I think, i already announced variable 'c'. So i thought the result of this code just print 2. what happened in this code?

I don't wanna correct this code, but i wanna know the reason of error.

chepner
  • 497,756
  • 71
  • 530
  • 681

0 Answers0