3 ms·
I wouldn't name a list l in real code. It was just the first thing that popped to mind. :-) And as was mentioned the "assert l" part is defending against l b
by j_baker 16y ago
I wouldn't name a list l in real code. It was just the first thing that popped to mind. :-)
And as was mentioned the "assert l" part is defending against l being None. I suppose I could be more explicit by saying "assert l is not None and len(l) == 1".
- jemfinch 16y agoYes, you should definitely should be more explicit if that's what you intend to check: PEP8 makes that explicit. I'm not sure why you'd defend against None anyway. Why defend against None, but not against 3.1459 or 4j or ''?
- statictype 16y agoThere's nothing wrong with `is l`. Sounds like you're just splitting hairs. He's defending against None because calling __len__ on None results in an exception. 3.14159 also results in an exception but it's far more likely that the object passed was None than that it was a completely different type than the one expected.
- jemfinch 16y ago> it's far more likely that the object passed was None than that it was a completely different type than the one expected. FYI, None is a completely different type than the one expected.