2 ms·
`[] + []` is unlikely to happen except by accident if you don't know that's how array concatenation is done in JavaScript. But wanting to provide default value
by xdennis 4y ago
`[] + []` is unlikely to happen except by accident if you don't know that's how array concatenation is done in JavaScript.
But wanting to provide default values of [] is quite common in Python. Seeing this workaround is quite common in Python:
def func(arg=None):
if arg is None:
arg = []
...
- reportgunner 4y agoI'm talking about the following where we don't intend to do [] + [] but we feed some lists to some functions that do something to the lists and we end up with empty lists in some cases without inspecting the contents of a and b after we feed it to the functions. Why would you define a default argument of an empty list if you're not gonna check if it's a list and if it's empty? a = [1,2] someFunction(a) b = [3,4] someOtherFunction(b) a + b