A question on modification of a list via a function invocation
Steve D'Aprano
steve+python at pearwood.info
Mon Sep 4 10:43:41 EDT 2017
On Mon, 4 Sep 2017 11:30 pm, Antoon Pardon wrote:
> Op 04-09-17 om 15:24 schreef Steve D'Aprano:
>> I accept that many people dislike, or do not understand, conceptual models
>> where objects can be in more than one location at once. For many people,
>> dropping into the implementation and talking about references is easier to
>> understand. But that doesn't make it essential.
>>
>> The semantics of Python is that we assign objects to names, not references to
>> objects to names. There's no "get reference" or "address of" operation in
>> Python. We write:
>
> What does that mean assigning objects to names?
Would it help if I use the term "bind" instead?
All values in Python are objects. Assignment looks like this:
target = expression
and Python evaluates the expression on the right, producing an object, and then
binds it to the target in the left.
The target is often a simple name, like:
foo = 1
but if you want to be pedantic[1] the target can also be more complicated:
func(arg).foo[bar] = 1
The glossary unfortunately doesn't define either name binding or assignment:
https://docs.python.org/3/glossary.html
but the Language Reference describes name binding:
https://docs.python.org/3/reference/executionmodel.html#naming-and-binding
and Wikipedia has a good description of it:
https://en.wikipedia.org/wiki/Name_binding
[1] And why not, I would if I were in your position *wink*
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list