Why should I refer to “names” and “binding” in Python instead of “variables” and “assignment”?

In C and C++, a variable is a named memory location. The value of the variable is the value stored in that location. Assign to the variable and you modify that value. So the variable is the memory location, not the name for it.

In Python, a variable is a name used to refer to an object. The value of the variable is that object. So far sounds like the same thing. But assign to the variable and you don’t modify the object itself, rather you alter which object the variable refers to. So the variable is the name, not the object.

For this reason, if you’re considering the properties of Python in the abstract, or if you’re talking about multiple languages at once, then it’s useful to use different names for these two different things. To keep things straight you might avoid talking about variables in Python, and refer to what the assignment operator does as “binding” rather than “assignment”.

Note that The Python grammar talks about “assignments” as a kind of statement, not “bindings”. At least some of the Python documentation calls names variables. So in the context of Python alone, it’s not incorrect to do the same. Different definitions for jargon words apply in different contexts.

Leave a Comment