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


Groups > comp.lang.python > #99723

Re: variable vs. object

From Nagy László Zsolt <gandalf@shopzeus.com>
Newsgroups comp.lang.python
Subject Re: variable vs. object
Date 2015-11-30 09:09 +0100
Message-ID <mailman.21.1448870980.14615.python-list@python.org> (permalink)
References <2b4696d5-c9fb-4ca6-92a3-564e47712d59@googlegroups.com>

Show all headers | View raw


> a=10
>
> 'a' is an integer. Is it an object too?
In Python, objects have an identity. When you do "a=10" then you *bind*
the object to the name *a*. By "variable", the documentation refers to a
name that was bound to an object. This is different from many other low
level languages. For example: in C, you can do

a=10;

And it will "set the value of the variable 'a' to 10". In other words:
"a" is not just a name, it refers to a certain location in memory where
an integer value is stored. And in C, it is not an object but a value of
a built-in type.

In contrast, this is what happens in Python:

  * An "Integer" object is constructed with the value 10.
  * This object is then bound to the name "a".

The key point is that "variables" are just names that may reference to
objects. There is a distinction between names and objects. Strictly
speaking, you cannot "set the value of a variable", because variables do
not hold values. They just refer to objects. In Python, you can only
"create an object", or "change the state of an object", and "bind a name
to an object".

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


Thread

variable vs. object fl <rxjwg98@gmail.com> - 2015-11-29 18:06 -0800
  Re: variable vs. object Joel Goldstick <joel.goldstick@gmail.com> - 2015-11-29 21:16 -0500
  Re: variable vs. object André Roberge <andre.roberge@gmail.com> - 2015-11-29 18:24 -0800
    Re: variable vs. object Ben Finney <ben+python@benfinney.id.au> - 2015-11-30 13:45 +1100
  Re: variable vs. object Ben Finney <ben+python@benfinney.id.au> - 2015-11-30 13:41 +1100
  Re: variable vs. object Marko Rauhamaa <marko@pacujo.net> - 2015-11-30 07:28 +0200
  Re: variable vs. object Nagy László Zsolt <gandalf@shopzeus.com> - 2015-11-30 09:09 +0100
  Re: variable vs. object Chris Angelico <rosuav@gmail.com> - 2015-11-30 19:19 +1100

csiph-web