Tools, FAQ, Tutorials:
'if ... elif ... else' Conditional Statement Blocks
How to enter "if ... elif ... else" statement blocks in Python code?
✍: FYIcenter.com
"if ... elif ... else" statement blocks allow you to execute statement blocks conditionally.
When "if ... elif ... else" statement blocks are interpreted, only the first statement block that is associated to a condition returning True gets executed.
"if ... elif ... else" statement blocks can be entered in Python code using the following syntax:
if condition :
statement-block
elif condition :
statement-block
...
else :
statement-block
For example:
>>> x = 2
>>> msg = None
>>> if x < 0:
... msg = "Negative"
... x = 0
... elif x == 0:
... msg = "Zero"
... elif x == 1:
... msg = "Single"
... else:
... msg = "More"
...
>>> print("Message: "+msg)
Message: More
Note that Python uses indentation (leading spaces at the beginning of the statement) to indicate a sub statement block.
⇒ 'for ... in ... else' Repeating Statement Blocks
2023-06-12, ∼2507🔥, 0💬
Popular Posts:
How to extend json.JSONEncoder class? I want to encode other Python data types to JSON. If you encod...
How To Merge Cells in a Column? If you want to merge multiple cells vertically in a row, you need to...
How to use the "set-backend-service" Policy Statement for an Azure API service operation? The "set-b...
Where to get a JSON.stringify() Example Code in JavaScript? Here is a good JSON.stringify() example ...
Where to get a real Atom XML example? You can follow this tutorial to get a real Atom XML example: 1...