<div dir="ltr"><div><div><div><div><div><div><div><br></div>What do educators think about this discussion of variables in Python?<br><br><a href="http://www.python-course.eu/variables.php">http://www.python-course.eu/variables.php</a><br><br></div>I find the "variable versus identifier" discussion, with repeated references to C / C++, to be somewhat on the confusing side.<br><br></div>My view is "variable as container" makes sense if you're talking about the object itself, on the heap, e.g. the list, dict or tuple or whatever.  <br><br>I might write the word "Object" with a big "O" and say that represents "a container in memory" (contains data and methods e.g. datetime.datetime objects).<br><br></div>But then I'd say said object is "variable" only if it's mutable i.e. it could be a constant (immutable) in contrast.  Strings and integers are not "variables" as you can't do anything to mutate them.  Lists are variables, strings are not.<br><br></div>Names, on the other hand, are like postits or luggage tags, more like labels for objects, and we can pull a postit (like X) from an object (like 'A') and stick it on another object (say 3) instead.   <br><br>This is *not* a matter of a variable changing i.e. <br><br>X = 'A' <br>X = 3 <br><br>has nothing to do with "changing the content of a container" (as if 3 had to fit into the same piece of memory as the 'A' did) but is rather about slapping the name 'X' onto two different objects in quick succession.  Identifiers don't care what they stick to, as long as they're objects.<br><br></div>Objects always have type.  <br><br>Names are just names:  they name things with type, i.e. objects.  <br><br>It's not that mysterious -- but the "container" metaphor gets in the way when you go:<br><br></div><div>>>> A = [1,2,3]<br></div><div>>>> B = A<br></div><div>>>> B[-1]=4<br></div><div>>>> A[2]<br>4<br><br></div><div>and then maybe think A should be pictured as a container with [1,2,3] inside it.  So does B have [1,2,3] inside it too, meaning it's own copy?  Of course not, but two "containers" cannot logically "contain" the same object which is why there's cognitive stress.  The "container" metaphor is obstructive.<br><br></div><div>B and A are simply two postits, two tags, affixed to the same object, the list on the heap, no big deal.  <br><br>You can call that object a "variable" if you like, but why not just call it a "mutable object" instead?  <br><br>On the other hand, A and B are just names in the namespace.  We use them to talk to / remotely control said objects, not just name them.  Names don't have type and we don't name names, we name objects.<br><br></div><div>A name is a lot like a TV remote, with lots of buttons (dot notation activated, lots of little callables).  An object is a lot like the TV.  <br><br>More than one remote controlling the same TV is OK in Python.  <br><br>There is no "container" in this picture unless you want to say the TV is a container (an object), in which case I'd agree.  Saying the remote "contains" the TV is not helpful and just gets in the way the second you have two remotes for the same object.<br><br></div><div>Kirby<br><br></div><br></div>