How to Teach Python "Variables"

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Nov 26 17:23:41 EST 2007


On Mon, 26 Nov 2007 21:37:19 +1300, greg wrote:

> none wrote:
>>     IIRC, I once saw an explanation how Python doesn't have "variables"
>> in the sense that, say, C does, and instead has bindings from names to
>> objects.
> 
> If you're talking to C programmers, just tell them that Python variables
> always contain pointers. That should give them the right mental model to
> build on.

Until they wonder why this doesn't work.


x = 1  # x points to 1
y = x
assert x is y  # confirm y points to the same memory location as x
x += 1
assert y == 2  # so naturally y should be incremented as well



-- 
Steven



More information about the Python-list mailing list