[Python-Dev] PEP 572 and assert (original) (raw)

Barry Warsaw barry at python.org
Tue Jul 17 15:58:42 EDT 2018


On Jul 17, 2018, at 12:18, MRAB <python at mrabarnett.plus.com> wrote:

Why use len(...) == 0 instead of not(...)?

assert not(subdirs := list(path.iterdir())), subdirs

Off-topic, but it’s a style thing. Some style guides (and my personal preference) require to be more explicit when checking for empty sequences. I’ll use a boolean test (e.g. not or false-iness) when the subject could be empty, None, or the empty string, and len() == 0 when the subject is supposed to be a sequence.

-Barry

-------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: Message signed with OpenPGP URL: <http://mail.python.org/pipermail/python-dev/attachments/20180717/ee5a6c64/attachment.sig>



More information about the Python-Dev mailing list