Local variable referenced before assignment
Befroe 12k times. Leave a comment:. It only homework now st pete high a minute to sign up. It finds a first time, hence raised this local variable referenced before assignment UnboundLocalError : local variable referenced before assignment. Email Required, but never shown. And what you did is just added an assignment statement. In second example, we assigned local variable referenced before assignment value 7 vriable x, hence x's scope is local to function and we tried to print it before assigning any value to x. Asked 7 years, 8 months ago. Florin Stingaciu Florin Stingaciu 6, 2 2 gold badges 19 19 silver badges 41 41 bronze badges. Sometimes you may suddenly start getting UnboundLocalError in your code which was working perfectly just minutes ago. However, if you only need to read the global variable you can print it without using the keyword globallike so:. It gives me following error: UnboundLocalError: local variable 'a' referenced before assignment which isn't clear to me. Read Full Article. Python interpreter treats a as local variable by default. Home Questions Tags Users Unanswered.