官术网_书友最值得收藏!

The if...elif condition

The if...elif ladder, popularly known as if...else if in other programming languages such as C, C ++, and Java, has the same function in Python. An if condition let's us specify a condition alongside the else part of the code. Only if the condition is true is the section proceeding the conditional statement executed:

a=44
b=66
if a > b:
print("a is Greater")
elif b > a:
print("B is either Greater or Equal")
else:
print("A and B are equal")
print("End")

It must be noted that the third else in the preceding code snippet is optional. Even if we don't specify it, the code works just fine:

Let's create a file named if_el_if.py, and see how this can be used:

主站蜘蛛池模板: 海城市| 古丈县| 高安市| 眉山市| 宣城市| 温宿县| 郎溪县| 安顺市| 鲜城| 聊城市| 葵青区| 潍坊市| 弥勒县| 泗水县| 沐川县| 弥渡县| 二手房| 大港区| 太仓市| 张家界市| 汽车| 玛纳斯县| 安图县| 政和县| 忻州市| 和顺县| 屯门区| 马山县| 平南县| 望江县| 邳州市| 阜康市| 沙田区| 荆门市| 郑州市| 志丹县| 正宁县| 江永县| 扎赉特旗| 若尔盖县| 苍溪县|