variable vs. object

Ben Finney ben+python at benfinney.id.au
Sun Nov 29 21:45:55 EST 2015


André Roberge <andre.roberge at gmail.com> writes:

> In Python, a "variable" is a name given to an object. In Python, the
> "=" sign is used to assign a name to an object: the name is on the
> left-hand side, and the object is on the right hand side. Multiple
> names can be assigned to the same object.

Take care with the directionality of those statements.

In Python we don't give the name *to* the object, which would imply that
the object “has” that name in some sense. The object is totally
unaffected, and assignment does not give the object any knowledge about
that name.

We also don't assign names *to* objects; if anything, we assign the
object to the name.

It is the name that “has” the object. Or perhaps less confusingly, the
name is *bound to* the object.

It is frequently a point of confusion that assignment *never* affects
the object, so it's best to avoid giving that false impression.

> In the example you gave, "a" is a name given to the object "10" which
> is an integer.

Rather, I'd prefer to say that ‘a’ now refers to the object ‘10’. The
object ‘10’ was not “given” anything.

-- 
 \       “When I get new information, I change my position. What, sir, |
  `\             do you do with new information?” —John Maynard Keynes |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list