3 ms·
I figured readers could fill in the relevant blanks. Updated example: if something: value = do something else: if something_else: v
by johnmaguire2013 11y ago
I figured readers could fill in the relevant blanks. Updated example:
if something:
value = do something
else:
if something_else:
value = do something else
else:
value = do a third thing
As I said in my initial post, "it helps once you have nested ifs, and multiple lines of code." Here's the change:
if something:
return do something
if something_else:
return do something else
return do a third thing
Again, what I'm stressing here is that if you already have your result, you can return, and it makes the code easier to follow than adding a superfluous "else:" statement.