Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

Why should I refer to "names" and "binding" in Python instead of "variables" and "assignment"? I know this question is a bit general but I really would like to know :)

like image 745
BoJack Horseman Avatar asked Dec 20 '13 08:12

BoJack Horseman


People also ask

What is the difference between name and variable in Python?

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.

What is binding of variables in Python?

Rebinding a variable When you rebind a variable, you are changing the object to which the variable name refers.

Is Python assignment by value or reference?

Python moves arguments through assignment, so neither by Reference nor with value. The logic for this is two-fold: Currently, the parameter passing in is a pointer to an object.

What is the purpose of a variable name in Python?

A Python variable is a symbolic name that is a reference or pointer to an object. Once an object is assigned to a variable, you can refer to the object by that name. But the data itself is still contained within the object.


1 Answers

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.

like image 179
Steve Jessop Avatar answered Sep 27 '22 23:09

Steve Jessop