Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52286

Re: beginner question (True False help)

Date 2013-08-10 01:39 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: beginner question (True False help)
References <6c6dedec-5e47-4229-bc67-01b058cdb410@googlegroups.com> <d8ea3662-cab6-4571-87f5-dc82d5c34b8a@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.414.1376095190.1251.python-list@python.org> (permalink)

Show all headers | View raw


On 10/08/2013 00:40, eschneider92@comcast.net wrote:
> (I forgot to post this with my last post.)
> Also, I don't understand any part of the following example, so there's no specific line that's confusing me. Thanks for the help btw.
>
You don't understand _any_ of it?


 > var = 42

Here you're assigning to 'var'. You're not in a function, so 'var' is a
global variable.

> def  myfunc():
 >       var = 90

Here you're assigning to 'var'. If you assign to a variable anywhere in
a function, and you don't say that that variable is global, then it's
treated as being local to that function, and completely unrelated to
any other variable outside that function.
>
> print "before:", var
> myfunc()
> print "after:", var
>
> def myfunc():
>      global var
>      var = 90
>
Here you're assigning to 'var', but this time you've declared that it's
global, so you're assigning to the global variable called 'var'.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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