The “does Python have variables?” debate

Ned Batchelder ned at nedbatchelder.com
Wed May 7 21:33:01 EDT 2014


On 5/7/14 8:35 PM, 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]
>

Can we make this concrete by speaking about a specific language?  I 
don't recognize this.  I thought we were concerned with beginners 
incorrectly thinking Python worked like C, but this is nothing like C.

-- 
Ned Batchelder, http://nedbatchelder.com




More information about the Python-list mailing list