@@ -101,6 +103,69 @@ Also, [take care with handling mutables as arguments and as default arguments](h
also explained [here](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values) and [here](https://docs.python-guide.org/writing/gotchas/)
(common gotchas).
From [Scopes an Namespaces](https://docs.python.org/3/tutorial/classes.html#python-scopes-and-namespaces), telling that assignments bind names to objects:
A special quirk of Python is that – if no global statement is in effect –
assignments to names always go into the innermost scope. Assignments do not
copy data — they just bind names to objects. The same is true for deletions:
the statement del x removes the binding of x from the namespace referenced by
the local scope. In fact, all operations that introduce new names use the local
scope: in particular, import statements and function definitions bind the
module or function name in the local scope.
The global statement can be used to indicate that particular variables live in
the global scope and should be rebound there; the nonlocal statement indicates
that particular variables live in an enclosing scope and should be rebound
there.
[...]
Actually, you may have guessed the answer: the special thing about methods is
that the instance object is passed as the first argument of the function. In
our example, the call x.f() is exactly equivalent to MyClass.f(x). In general,
calling a method with a list of n arguments is equivalent to calling the
corresponding function with an argument list that is created by inserting the
method’s instance object before the first argument.