Python Forum
variable referenced before assignment
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
variable referenced before assignment
#2
Each function has it's own scope. The function, which is called in main() could not access to the local variables of main.

The function estim does not see the variable estimation. How could a function evaluate this statement, when estimation is unknown?
estimation = (estimation + number / estimation) / 2
This error happens also, when you've assigned a global variable (on module level) and try to assign a new object to this name inside a function. You can use global, but you should avoid this. You can assign the object, which is referenced by a global name (variable) to a local name inside your function. Then you can do afterwards a new assignment to the local variable, which don't have an effect on the global variable.

In Python you're referencing by name.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
variable referenced before assignment - by Niko047 - Aug-02-2017, 09:43 PM
RE: variable referenced before assignment - by DeaD_EyE - Aug-02-2017, 10:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rounding exercise: UnboundLocalError: local variable referenced before assignment Drone4four 5 3,477 Sep-06-2020, 09:01 AM
Last Post: ibreeden
  UnboundLocalError: local variable 'a' referenced before assignment fad3r 3 16,586 Jun-20-2018, 05:43 PM
Last Post: nilamo
  why am I getting "local variable 'x' referenced before assignment"? wlsa 6 9,158 Jun-16-2018, 05:31 PM
Last Post: buran
  local variable 'l' referenced before assignment... darkreaper1959 4 7,495 Jan-21-2017, 08:16 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020