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
2017-09-12, 1089👍, 0💬
Popular Posts:
How to pull NVIDIA CUDA Docker Image with the "docker image pull nvidia/cuda" command? If you are ru...
How to add request query string Parameters to my Azure API operation to make it more user friendly? ...
Where to see resource detailed information of my API Management Service on Azure Portal? Once you ha...
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...
Where to find tutorials on the 2017 version of API Management Services at Azure Portal? Here is a li...