It depends what you want to do.
Here we have two independent if-blocks:
The second block after elif is not executed, because the first condition was true.
So only one if/elif/else-block is executed.
Here we have two independent if-blocks:
def foo(text, upper, strip): if upper: text = text.upper() if strip: text = text.strip() return text foo(' Hello World ', True, True)But writing this with elif gives different results.
def foo(text, upper, strip): if upper: text = text.upper() elif strip: text = text.strip() return text foo(' Hello World ', True, True)In this case upper is also True and the code-block is executed.
The second block after elif is not executed, because the first condition was true.
So only one if/elif/else-block is executed.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!