3 ms·
ES6 got this right too. This design decision makes me die a little every time I have to do: def foo(x=None): if not x: x = [] ...
by eiopa 11y ago
ES6 got this right too.
This design decision makes me die a little every time I have to do:
def foo(x=None):
if not x:
x = []
...
- dajonker 11y agoThat will get you into trouble as well, please use: if x is None: x = [] ... etc.
- switch007 11y agoOr even "prettier": x = [] if x is None else x
- knite 11y agoI'm partial to: x = x or []
- acveilleux 11y agoOnly works when x is truthy for all legal x values, excluding x=0.