6 ms·
You're right. PEP8 says: > beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to No
by freyr 9y ago
You're right. PEP8 says:
> beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context!
This should apply to the contains_zero function as well. It seems a little murky when PEP8 recommends checking whether a sequence type is empty,
Yes: if not seq:
if seq:
No: if len(seq):
if not len(seq):
if seq were accidentally set to False or 0. But I guess that would be revealed as soon as you start treating seq like a sequence.