Question to pythonistas out there: Is it acceptable to reduce indentation by doing:
if blah:
# do stuff
return
# do lots of other stuff
instead of:
if blah:
# do stuff
else:
# do lots of other stuff
Question to pythonistas out there: Is it acceptable to reduce indentation by doing:
if blah:
# do stuff
return
# do lots of other stuff
instead of:
if blah:
# do stuff
else:
# do lots of other stuff
i.e. I read the first as "if blah, stop what you would normally do and do this instead"
👍 to @mispy, this is how I tend to write any of my code.
I generally use them to convey slightly different things. The former indicates that "blah" is an unusual case that should be handled separately, while the rest of the code is a more common path. The latter suggests more expected/constrained variation.