The “does Python have variables?” debate

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed May 7 21:32:15 EDT 2014


On Thu, 08 May 2014 10:35:46 +1000, Ben Finney wrote:

> Marko Rauhamaa <marko at pacujo.net> writes:
> 
>> Ben Finney <ben at benfinney.id.au>:
>>
>> > That's why I always try to say “Python doesn't have variables the way
>> > you might know from many other languages”,
>>
>> Please elaborate. To me, Python variables are like variables in all
>> programming languages I know.
> 
> Many established and still-popular languages have the following
> behaviour::
> 
>     # pseudocode
>     foo = [1, 2, 3]
>     bar = foo          # bar gets the value [1, 2, 3] 
>     assert foo == bar  # succeeds
>     foo[1] = "spam"    # foo is now == [1, "spam", 3] 
>     assert foo == bar  # FAILS, ‘bar’ == [1, 2, 3]

Pascal and Fortran are examples of this.

Any more recent examples? Any examples of languages with dynamic typing 
but this behaviour?

I note also that one may still have a name-binding model with copy-on-
assign semantics. For example, one might add syntactic sugar to a Python-
like language such that:

    spam = eggs

is a name binding, and 

    spam := eggs

makes a copy of eggs before binding.



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/



More information about the Python-list mailing list