Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'variables': 0.07; 'subject:help': 0.08; 'restriction': 0.09; 'variables.': 0.09; 'subject:question': 0.10; 'cc:addr:python- list': 0.11; 'python': 0.11; 'def': 0.12; '"a"': 0.16; '"global"': 0.16; "function's": 0.16; 'function()': 0.16; 'scope,': 0.16; 'scope.': 0.16; 'scopes': 0.16; 'subject:beginner': 0.16; 'applies': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'do.': 0.18; 'variable': 0.18; 'programming': 0.22; 'cc:addr:python.org': 0.22; '(such': 0.24; 'refers': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'too.': 0.31; 'prints': 0.31; 'file': 0.32; 'languages': 0.32; "we're": 0.32; 'subject: (': 0.35; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'accessing': 0.36; 'does': 0.39; 'most': 0.60; 'august': 0.61; 'new': 0.61; 'more': 0.64; 'different': 0.65; 'within': 0.65; '100': 0.79; 'subject:True': 0.91; 'to:addr:comcast.net': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=OsgCVuXkW5c37XQa04LyXUkCibMbILqbk2fUPXDHeUA=; b=zZujA/NeatlWoSU/50t7to/t42KUscSPcdldoUAyvzlfjTB+GNtmaYIXeVQz0f/i9f Ni6cQsT3m/Rt1j9C1dGvnDB07lyGw+2ohowAt/B7gI0yaI9Jppam83K8apsnp8HB+sNu 0z9jja/a6vH/8Y0Dg9TiJFSx8lL5ITHomJHdqBlpcwhTQ7kVEuJWat824HBjOj8RuVfP nCbFQWHMX9OvlnGggfBT675biM1lJPLVWV4Z5z3wghsXIJgAudsU6Voq0jrOSO1NZPdS oM1paG3a5OJeDCJQt2xPSF0K/M0BsaFy2F7JmSiVE6iGMDQ1N17ZwOgF5ybqGdfsFSdl dHNw== X-Received: by 10.112.34.178 with SMTP id a18mr1196029lbj.67.1376097761421; Fri, 09 Aug 2013 18:22:41 -0700 (PDT) MIME-Version: 1.0 Sender: joshua.landau.ws@gmail.com In-Reply-To: <35939249-9d6f-46ac-b0b6-6ab8152cdae9@googlegroups.com> References: <6c6dedec-5e47-4229-bc67-01b058cdb410@googlegroups.com> <35939249-9d6f-46ac-b0b6-6ab8152cdae9@googlegroups.com> From: Joshua Landau Date: Sat, 10 Aug 2013 02:22:01 +0100 X-Google-Sender-Auth: LIeFpVPcKGW4D2EVLj32wdFYOiw Subject: Re: beginner question (True False help) To: kurt schwitters Content-Type: text/plain; charset=UTF-8 Cc: python-list 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: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376097771 news.xs4all.nl 15876 [2001:888:2000:d::a6]:51533 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52291 On 10 August 2013 00:34, wrote: > What does global mean? Python has "scopes" for its variables. Most programming languages do. A "scope" is a restriction on where variables exist -- they exist only within the scope. This can be seen in this example: def function(): # A new "scope" is made when you enter a function variable = 100 function() print(variable) # Error, as variable doesn't exist outside of "function"'s scope There are lots of different "scopes" in code. Every function has one, and there are some more too. One of the scopes is the "global" scope. This is the scope *outside* of all the functions and other scopes. Everything in the file is within this sope: # Make in global scope variable = 100 def function(): # Works because we're inside the global scope print(variable) # Prints "100" function() So "a = b" inside the function applies to the function's scope, but when accessing variables (such as "print(variable)") it will look in all of the outer scopes too. If you want to write "a = b" inside the function and change the global scope, you need to say that "a" refers to the "a" in the global scope. You do that like this: def function(): # "variable" is in the global scope, not the functions' global variable variable = 100 function() # Prints "100" print(variable) Does that help you understand what "global" means?