Python Confused in name binding in python

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
  • Tags Tags
    Confused Python
AI Thread Summary
Name binding in Python refers to how variable names are associated with objects in memory. For example, when x=1, the name x is linked to the object 1, and subsequently, z=x means z also references the same object. The discussion highlights that changing the value of x, such as x=y where y=2, updates the binding of x to the new object. A practical application of name binding is illustrated in the my_sum function, which demonstrates how variable assignments accumulate a sum from a list. Understanding name binding is essential for grasping how variables interact and change in programming.
shivajikobardan
Messages
637
Reaction score
54
(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.
 
Technology news on Phys.org
Assignment x = e evaluates the expression e and stores its result in variable x.

shivajikobardan said:
I can't see how this simple concept can have any use in programming.
Assignment is useful in the following code.

Python:
def my_sum(lst):
  s = 0
  for x in lst:
    s = s + x
  return s

>>> my_sum([1,2,3])
6
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
1
Views
2K
Replies
2
Views
898
Replies
10
Views
3K
Replies
6
Views
2K
Replies
4
Views
2K
Replies
5
Views
2K
Back
Top