Short answer is: they are assigned in order, left-to-right.
When you declare a user-defined function or method, you give a name. Then if this function/method requires one or more inputs in order to work, you then declare a list of parameters. Still with me?
The parameter list can be one or more parameters, separated by a comma. You give each a variable name.
As a side note, that variable belongs to the function. It’s scope, meaning who can access it, belongs to that function.
When you want that function to run, you call (invoke) it and pass in the values that it needs to do it’s work. These arguments are assigned in order, left-to-right, to the function’s parameters.
def __init__(self, name, age):
# code goes here
rhino = Animal('Bob', 38)
- the object references itself in the first parameter named
self. That happens behind the scenes, as Python takes care of it for you
'Bob' is the 1st argument and gets assigned to the
38 is the 2nd argument and gets assigned to the next parameter from the left, which is
Does that make sense?
BTW Most programming languages work this way.
To improve readability, name your variables purposefully to tell you what data they represent. Name your functions by the expected behavior that will occur when you call it. And name functions starting with a verb, as they are your workers.