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


Groups > comp.lang.python > #55156

Re: Python variables?

Date 2013-09-30 21:28 -0400
From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: Python variables?
References (3 earlier) <5249ECFE.2050402@nedbatchelder.com> <5249F4EE.60604@stoneleaf.us> <7wr4c6rl6a.fsf@benfinney.id.au> <mailman.524.1380584880.18130.python-list@python.org> <524a1f5c$0$29974$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.528.1380591267.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 9/30/13 9:03 PM, Steven D'Aprano wrote:
> On Mon, 30 Sep 2013 19:47:49 -0400, Ned Batchelder wrote:
>
>> On 9/30/13 6:37 PM, Ben Finney wrote:
>>> Ethan Furman <ethan@stoneleaf.us> writes:
>>>
>>>>   From [Ned Batchelder]'s blog:
>>>>> Names are Python's variables: they refer to values, and
>>>>>    those values can change (vary) over the course of your program.
>>>> This is partially incorrect.  If the value referred to by the name is
>>>> immutable, then it cannot change; perhaps you meant to say that which
>>>> object the name points to can vary over time?
>>> I agree. Names are not Python's variables.
>>>
>>> If anything in Python is a “variable” as generally understood, it is
>>> not a name. It is a *binding*, from a reference (a name, or some other
>>> reference like a list item) to a value.
>>>
>>> It is the binding which can change over the course of the program, so
>>> that is the variable.
>>>
>>>
>> True, but no one calls the binding the variable.  Here is a program:
>>
>>       x = 4
>>
>> Every one of us is perfectly comfortable talking about the variable x.
>> Don't get hung up on implementation pedantry.  The name x here refers to
>> 4.  Later it could refer to "four".  The value associated with the name
>> x changed.  x is a variable.
> Your statement is ambiguous -- do you mean the *association* between
> value (object) and name changed, or the value which is associated with
> the name changed?

Yes, my statement was ambiguous.  The value of x at time t1 can be 
different than the value of x at time t2, and there are two different 
ways it can differ.  None of that changes the fact that the value 
associated with the name varies over the course of a program, giving 
rise to "variables."

I prefer to say that Python has variables, and they work by a mechanism 
of names referring to values.  I don't find that beginners get it by 
being told that Python has no variables.  It seems to be something that 
experts sometimes find helpful, though.

--Ned.
>
> In the first case, "the value associated with the name x changed" is no
> different from saying "the name binding changed", only longer and more
> ambiguous.
>
> In the second case, if you mean that the association remains the same,
> but the value itself changed, that's demonstrably untrue since 4 is
> immutable. But you know that :-)
>
> I straddle the fence on this dispute... I'll often refer to Python
> variables when, in my option, it doesn't confuse the issue or introduce
> ambiguity, but I feel guilty doing so :-) And I always look for the
> opportunity to introduce the concept of name binding into the discussion.
> I'm just not religious about it.
>
>

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


Thread

class implementation markotaht@gmail.com - 2013-09-30 01:43 -0700
  Re: class implementation Peter Otten <__peter__@web.de> - 2013-09-30 11:03 +0200
  Re: class implementation markotaht@gmail.com - 2013-09-30 02:10 -0700
    Re: class implementation Peter Otten <__peter__@web.de> - 2013-09-30 11:27 +0200
  Re: class implementation markotaht@gmail.com - 2013-09-30 05:41 -0700
    Re: class implementation Peter Otten <__peter__@web.de> - 2013-09-30 15:02 +0200
    Re: class implementation Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-30 09:21 -0400
    Re: class implementation Piet van Oostrum <piet@vanoostrum.org> - 2013-09-30 13:32 -0400
    Re: class implementation Dave Angel <davea@davea.name> - 2013-09-30 19:34 +0000
      Re: class implementation 88888 Dihedral <dihedral88888@gmail.com> - 2013-10-01 00:01 -0700
    Re: class implementation Ned Batchelder <ned@nedbatchelder.com> - 2013-09-30 17:28 -0400
      Re: class implementation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-30 23:45 +0000
        Re: class implementation Ethan Furman <ethan@stoneleaf.us> - 2013-09-30 17:31 -0700
    Re: class implementation random832@fastmail.us - 2013-09-30 17:49 -0400
    Python variables?  [was Re: class implementation] Ethan Furman <ethan@stoneleaf.us> - 2013-09-30 15:02 -0700
    Re: Python variables? Ben Finney <ben+python@benfinney.id.au> - 2013-10-01 08:37 +1000
    Re: Python variables?  [was Re: class implementation] Ned Batchelder <ned@nedbatchelder.com> - 2013-09-30 19:45 -0400
      Re: Python variables?  [was Re: class implementation] "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2013-10-01 01:29 +0100
    Re: Python variables? Ned Batchelder <ned@nedbatchelder.com> - 2013-09-30 19:47 -0400
      Re: Python variables? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-01 01:03 +0000
        Re: Python variables? Ned Batchelder <ned@nedbatchelder.com> - 2013-09-30 21:28 -0400
    Re: class implementation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-01 00:19 +0000
  Re: class implementation markotaht@gmail.com - 2013-10-06 06:15 -0700
    Re: class implementation Terry Reedy <tjreedy@udel.edu> - 2013-10-06 15:52 -0400
    Re: class implementation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-07 01:24 +0000
  Re: class implementation markotaht@gmail.com - 2013-10-08 01:20 -0700
    Re: class implementation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-08 09:41 +0100
    Re: class implementation Dave Angel <davea@davea.name> - 2013-10-08 10:31 +0000
    Re: class implementation Cameron Simpson <cs@zip.com.au> - 2013-10-09 10:55 +1100
      Re: class implementation markotaht@gmail.com - 2013-10-10 11:34 -0700
        Re: class implementation Cameron Simpson <cs@zip.com.au> - 2013-10-11 09:07 +1100
        Re: class implementation Piet van Oostrum <piet@vanoostrum.org> - 2013-10-10 19:29 -0400
          Re: class implementation Ben Finney <ben+python@benfinney.id.au> - 2013-10-11 10:51 +1100
  Re: class implementation markotaht@gmail.com - 2013-10-08 07:05 -0700
    Re: class implementation "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2013-10-09 00:41 +0100

csiph-web