'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, 155👍, 0💬
Where to find tutorials on how to work with MySQL Database in PHP? A collection of tutorials to answ...
How To Use an Array as a Stack in PHP? A stack is a simple data structure that manages data elements...
How To Create a Table To Store Files in PHP? If you using MySQL database and want to store files in ...
How To Create a Directory in PHP? You can use the mkdir() function to create a directory. Here is a ...
Where to find tutorials on Python programming language? I want to learn Python. Here is a large coll...