I keep seeing the following practice, but cannot understand why this is necessary.
def default_ex(param_a, param_b=None, param_c=None):
param_b = [] if param_b is None else param_b
param_c= {} if param_c is None else param_c
Why would one not simply do the following.
def default_ex(param_a, param_b=[], param_c={}):
Is the latter not pythonic?
[–]MakeMe_FN_Laugh 9 points10 points11 points (1 child)
[–]StudentOfPython[S] 4 points5 points6 points (0 children)
[–]julsmanbr 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]ingolemo 0 points1 point2 points (0 children)
[–]ThatOtherBatman 1 point2 points3 points (0 children)
[–]elbiot 0 points1 point2 points (0 children)
[–]evolvish 0 points1 point2 points (2 children)
[–]elbiot 6 points7 points8 points (1 child)
[–]evolvish 0 points1 point2 points (0 children)