4 ms·
Ah, yeah, compared to the examples in the video that makes so much sense in a normal day to day application. I commonly do the following operations without much
by capableweb 4y ago
Ah, yeah, compared to the examples in the video that makes so much sense in a normal day to day application. I commonly do the following operations without much thought:
[] + []
{} + {}
[] + {}
{} + []
Great examples :)
The point is not what the data or naming of the functions/variables is, but what's happening when you run it...
- reportgunner 4y ago[] + [] is more likely to happen than taking list.append(value) and defining a function that does list.append(value) and then returns whatever list.append(value) returns. Hint: list.append(value) returns None
- 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