'if ... elif ... else' Conditional Statement Blocks
How to enter "if ... elif ... else" statement blocks in Python code?
"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
>>> 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.
2017-09-12, 200👍, 0💬
How the Values Are Ordered in an Array in PHP? PHP says that an array is an ordered map. But how the...
How To Quote Date and Time Values in SQL Statements in PHP? If you want to provide date and time val...
How To Create Table Borders? There are two sets of borders within a table: Outer Borders - Borders t...
How To Use Different Markers on Ordered List Items? By default, browsers will use decimal numbers as...
How To Sort an Array by Keys in PHP? Sorting an array by keys can be done by using the ksort() funct...