Confused in name binding in python

shivajikobardan

Junior Member
Joined
Nov 1, 2021
Messages
107
(I Didn't use code formatting here as I felt it was not necessary)

I have read multiple textbooks, articles and watched multiple videos about name binding in python.
Till now what I understand can be summarized in this-:
x=1 means name x is binded to object "1"
z=x and we know x=1

=> z=1

so z=x means z is binded to object 1
then,

y=2 #name y binds to object "2"
x=y #name x binds to object "2"

This is all I understand about name binding. I can't see how this simple concept can have any use in programming. This looks like math to me.
  1. I need 1 example program to understand things I asked here.
  2. I need 1 application of this concept
  3. I need a figure depicting what is exactly happening when we declare variable x=1 and when we later do x=5 then we do y=2 then x=y. What is happening inside the system? I want that with figures.
 
(I Didn't use code formatting here as I felt it was not necessary)

I have read multiple textbooks, articles and watched multiple videos about name binding in python.
Till now what I understand can be summarized in this-:
x=1 means name x is binded to object "1"
z=x and we know x=1

=> z=1

so z=x means z is binded to object 1
then,

y=2 #name y binds to object "2"
x=y #name x binds to object "2"

This is all I understand about name binding. I can't see how this simple concept can have any use in programming. This looks like math to me.
  1. I need 1 example program to understand things I asked here.
  2. I need 1 application of this concept
  3. I need a figure depicting what is exactly happening when we declare variable x=1 and when we later do x=5 then we do y=2 then x=y. What is happening inside the system? I want that with figures.
Don't know python. What's the difference between binding and assignment?
 
I've been using Python in a simplistic way for quite some time without ever bothering about bindings. But this thread prompted a search, so here goes (from https://ashtonkemerling.com/posts/binding-vs-assignment/):
Binding is used to create a new variable within the current context, while assignment can only change the value of a given variable within the narrowest bound scope.​

To my uneducated mind binding is simply the first assignment and in some sense a replacement for a variable declaration/definition in other languages. For example, in these two lines of code the first is a binding and the second is an assignment (provided this is the first occurence of 'x' in the code):
x = 5;​
x = 6;​
According to the same page, Python does not handle it too well by using the same symbol '=' for both.
 
I've been using Python in a simplistic way for quite some time without ever bothering about bindings. But this thread prompted a search, so here goes (from https://ashtonkemerling.com/posts/binding-vs-assignment/):
Binding is used to create a new variable within the current context, while assignment can only change the value of a given variable within the narrowest bound scope.​

To my uneducated mind binding is simply the first assignment and in some sense a replacement for a variable declaration/definition in other languages. For example, in these two lines of code the first is a binding and the second is an assignment (provided this is the first occurence of 'x' in the code):
x = 5;​
x = 6;​
According to the same page, Python does not handle it too well by using the same symbol '=' for both.
After reading the linked article I think I'll stick with C.
 
After reading the linked article I think I'll stick with C.
C is great, but not for every job.
I first started using Python as a scripting language, mostly involving simple text processing.
Then I've realized that it's quite good for handling non-trivial data structures. Kind of like C++ STL, but easier to use.
At some point I've discovered NumPy and started using it for numerical tasks instead of Octave/MatLab.
And if one ventures into neural nets/machine learning, then Python seems indispensable.
 
C is great, but not for every job.
I first started using Python as a scripting language, mostly involving simple text processing.
Then I've realized that it's quite good for handling non-trivial data structures. Kind of like C++ STL, but easier to use.
At some point I've discovered NumPy and started using it for numerical tasks instead of Octave/MatLab.
And if one ventures into neural nets/machine learning, then Python seems indispensable.
I was kidding. I've been using C at the same place for 30 years - I don't know enough about other languages to make informed comparisons.
 
Top