Because the default arguments are only executed once, when the function is compiled.
From the Docs:
Default parameter values are evaluated when the function definition is
executed. This means that the expression is evaluated once, when the
function is defined, and that the same “pre-computed” value is used
for each call. T
you can try something like this:
In [10]: def printNumber(num=None):
return num if num is not None else random()
....:
In [12]: printNumber()
Out[12]: 0.9620725546432438
In [13]: printNumber()
Out[13]: 0.8188258892156928
In [15]: printNumber(10)
Out[15]: 10