jf...@ms4.hinet.net writes: > In the first situation, the local variable 'counter' can be referenced > correctly. But in the second, why a statement added after the print() > statement can makes this variable "disappear", even the print() won't > do the right thing. Isn't it wired? please help!
The Python FAQ answers this, even using an example the same as yours <URL:https://docs.python.org/3/faq/programming.html#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value>. -- \ “… a Microsoft Certified System Engineer is to information | `\ technology as a McDonalds Certified Food Specialist is to the | _o__) culinary arts.” —Michael Bacarella | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list