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

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:

主站蜘蛛池模板: 宜君县| 肃南| 扎囊县| 额济纳旗| 松江区| 上犹县| 靖江市| 广汉市| 黎城县| 盘山县| 克拉玛依市| 娱乐| 松潘县| 闽侯县| 泸定县| 山东省| 宜兰县| 怀宁县| 武功县| 南丰县| 新乐市| 洛浦县| 新化县| 临高县| 陈巴尔虎旗| 永年县| 马鞍山市| 井冈山市| 民权县| 秦皇岛市| 龙川县| 赤水市| 彰化市| 陇南市| 壤塘县| 三亚市| 民权县| 建湖县| 共和县| 新津县| 浑源县|