3 ms·
>If I need different behaviour between "value not provided" and "there aren't any of that thing", I would perform both checks (if x is None:/if not x:). They w
by crdoconnor 11y ago
>If I need different behaviour between "value not provided" and "there aren't any of that thing", I would perform both checks (if x is None:/if not x:).
They will both be true if x is None. What you probably want is actually:
if x is None:
and
if len(x) == 0:
- StavrosK 11y agoI know they'll both be true, the first one will return (or I'll use elif). You definitely want the falsy comparison, the second object may not have len defined.
- icebraining 11y agoYour code is brittle; it'll fail when I pass it a generator expression, and for no good reason.
- crdoconnor 11y agoIf I'm checking the length of what I think is a list and it turned out to be a generator I WANT it to fail.