I was surprised to see that in Python, the classes in the argument list of a function, are instantiated when the function is defined and not when the function is called.
Consider the following code
class A:
def __init__(self):
print("init method called")
def f(a=A()):
print("function f called")
f()
f()
This will give the following output:
init method called
function f called
function f called
Thus, only one object of class A is constructed in this program, and not one for each call of function f. Why is this, and is it a common trait for interpreted language?