Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:question': 0.10; 'python': 0.11; 'def': 0.12; '###': 0.16; 'at,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'url:faq': 0.16; 'wrote:': 0.18; 'advance.': 0.19; 'programming': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'faq': 0.24; 'section.': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'skip:- 40': 0.29; 'ok.': 0.31; 'received:132': 0.31; 'url:python': 0.33; 'could': 0.34; 'problem': 0.35; 'explains': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'url:3': 0.61; 'kindly': 0.61; 'provide': 0.64 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Wolfgang Maier Subject: Re: A syntax question Date: Mon, 10 Nov 2014 12:39:17 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: px1.ruf.uni-freiburg.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415619550 news.xs4all.nl 2973 [2001:888:2000:d::a6]:41222 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80461 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()