Misconceptions about arguments and parameters arise when students incorrectly match parameters and arguments. Good documentation in the function is generally helpful and should be encouraged. Students typically don’t see the value of documentation until such situations arise, so insisting on good documentation right from the beginning is a good idea. We address related best practices in the “Writing and Using Functions” blog.
Rules and conventions on matching arguments and parameters should be practiced through specially crafted examples. Such exercise problems can also include the scope of local variables defined in a function, the use of variables not defined in a function, and the impact of changing variables that are parameters. Here is an example that may help students understand rules and side effects:
def fun1(x, y): x = 25 print x+y def fun2(a, b): a = a + 1 return a+b s = 1 x = 20 y = 100 fun1(s, x) t = fun2(s, y) print s, t, x
generates the output
45 1 102 20
It can be especially confusing when arguments and parameters have the same name. While Python allows one to have identical variable names in the def statement of a function (parameters) and when the function is called (arguments), it is considered poor practice with potential for confusion. For example, we use
def computeCircleArea(xc, yc, xp, yp): and not
def computeCircleArea(px, py, qx, qy): (see What to avoid and what to do when writing functions)