Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52291
| 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 | <joshua.landau.ws@gmail.com> |
| 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 <joshua@landau.ws> |
| Date | Sat, 10 Aug 2013 02:22:01 +0100 |
| X-Google-Sender-Auth | LIeFpVPcKGW4D2EVLj32wdFYOiw |
| Subject | Re: beginner question (True False help) |
| To | kurt schwitters <eschneider92@comcast.net> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | python-list <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.415.1376097771.1251.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On 10 August 2013 00:34, <eschneider92@comcast.net> 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?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
beginner question (True False help) eschneider92@comcast.net - 2013-08-07 01:17 -0700
Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-07 09:42 +0100
Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-07 13:59 -0700
Re: beginner question (True False help) Dave Angel <davea@davea.name> - 2013-08-08 01:18 +0000
Re: beginner question (True False help) Larry Hudson <orgnut@yahoo.com> - 2013-08-07 19:49 -0700
Re: beginner question (True False help) wxjmfauth@gmail.com - 2013-08-07 23:20 -0700
Re: beginner question (True False help) Chris Angelico <rosuav@gmail.com> - 2013-08-08 12:41 +0100
Re: beginner question (True False help) Terry Reedy <tjreedy@udel.edu> - 2013-08-08 16:29 -0400
Re: beginner question (True False help) wxjmfauth@gmail.com - 2013-08-09 01:05 -0700
Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 15:27 -0700
Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 00:05 +0100
Re: beginner question (True False help) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-09 22:58 -0400
Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 15:28 -0700
Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:14 -0700
Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 00:30 +0100
Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:24 -0700
Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:34 -0700
Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 02:22 +0100
Re: beginner question (True False help) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-10 01:40 +0000
Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:40 -0700
Re: beginner question (True False help) MRAB <python@mrabarnett.plus.com> - 2013-08-10 01:39 +0100
Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:43 -0700
Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 18:08 -0700
csiph-web