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, 1309🔥, 0💬
Popular Posts:
How to run CMD Commands in Dockerfile to change Windows Docker images? When building a new Windows i...
How to reinstall npm with a node version manager? I am getting permission errors with the current ve...
How to use "xsl-transform" Azure API Policy Statement? The "xsl-transform" Policy Statement allows y...
How to use the "Ctrl-p Ctrl-q" sequence to detach console from the TTY terminal of container's runni...
How to add a new operation to an API on the Publisher Dashboard of an Azure API Management Service? ...