coding style - where to declare variables

Marko Rauhamaa marko at
Sun Jul 22 17:08:00 EDT 2018

Richard Damon <Richard at>:

>> On Jul 22, 2018, at 3:50 PM, Marko Rauhamaa <marko at> wrote:
>> I wish people stopped talking about "name binding" and "rebinding,"
>> which are simply posh synonyms for variable assignment. Properly, the
>> term "binding" comes from lambda calculus, whose semantics is defined
>> using "bound" and "free" variables. Lambda calculus doesn't have
>> assignment.
> Marko, I think the term binding makes sense in python due to how names
> work. In python and the following code:
> X = getit()
> Y = X
> X.changeit()
> In python, presuming getit() returns some form of object (so it has a
> changeit() member) then X and Y are bound to the same object, and
> changeit() will thus also affect the object that we see at Y.

Would you call it binding in this case:

   X[0]["z"] = getit()
   X[3]["q"] = X[0]["z"]

I think what you are talking about is more usually called "referencing."

> With a language with more ‘classical’ variable, the assignment of Y =
> X would normal make a copy of that object, so the value Y does not get
> changed by X.changeit().

I Java terms, all Python values are boxed. That's a very usual pattern
in virtually all programming languages (apart from FORTRAN).


More information about the Python-list mailing list