Local variable ‘local_min_lr’ referenced before assignment

‘local variable ‘local_min_lr’ referenced before assignment’

What does this mean and what we need to do here ?

1 Like
x = 3
def func():
    x = x + 3

func()

The error means you are referencing a variable before assigning any value to it. In python, all the variables are global. If you define variables inside a function they have local scope. In the above code x when we call func() we are trying to use the value of x in x+3 but we have not set any value of x in the first place.
The reason being when we use x= it makes the scope of the x variable local and it forgets about x=3, so now there is no value in x and hence we cannot calculate x+3.

1 Like

mmmmm, I see, thanks Kushaj :smile:

Hi! Does anyone here have an idea how to fix this?