You may want to read:

https://docs.python.org/3/faq/programming.html?highlight=global#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value

from the Python docs Programming FAQ section.
It explains your problem pretty well.

As others have hinted at, always provide concrete Python error messages and tracebacks instead of vague descriptions.

Best,
Wolfgang


On 11/10/2014 12:07 PM, Mok-Kong Shen wrote:

I don't understand the following phenomenon. Could someone kindly
explain it? Thanks in advance.

M. K. Shen

-------------------------------------------------

count=5

def test():
   print(count)
   if count==5:
     count+=0  ### Error message if this line is active, otherwise ok.
     print(count)
   return

test()

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to