But these arguments are assign only first time as can be seen on the next example. The number values cannot be modified thus they are save from following effects.
>>> def func(a=4):
>>> print a
>>> func(1)
1
>>> func()
4
As you can see, the default value is assigned only for the first time and for next calls it is permanently reused. It can be dangerous if you are not aware of it. The following design pattern can be used to avoid this danger.
>>> def func(a=[]):
>>> a.append(1)
>>> print a
>>> func()
[1]
>>> func()
[1, 1]
>>> func()
[1, 1, 1]
The first few lines in the previous function will inicialize new empty values, which will be specific for the actual function call. When it is necessary to use more complicated default values which will be modified in function body, than these objects should be cloned immediate after function header.
def func(a, b=None, c=None):
if b is None:
b = []
if c is None:
c = {}
#the function body
It can be said that default argument values are variant of static variables for function and such property can be very surprising for many programmers.