These two patterns produce the same results. Does it matter which one is used? Why?
I prefer the second, it has less indentation and just looks cleaner to me, but I haven't seen it used much (in the places I've been). I don't want to settle on something and use it all over if it's ill advised for some reason.
IF...ELSE
if not packages:
help('download')
else:
for p in packages:
do_download(p)
verify_md5(p)
etc(p)
IF...RETURN; IMPLICIT ELSE
if not packages:
help('download')
return
for p in packages:
do_download(p)
verify_md5(p)
etc(p)
It's a style thing... But I always prefer using else
. As you clearly indicate in your question caption not having an else
makes it implicit and I strongly believe in explicit code that is easy to read and understand.
Also from The Zen of Python
Explicit is better than implicit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With