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

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:

主站蜘蛛池模板: 简阳市| 恭城| 阿瓦提县| 介休市| 吉木乃县| 花莲市| 通山县| 汾阳市| 龙陵县| 山阴县| 岳阳市| 汪清县| 梁平县| 吉木乃县| 响水县| 分宜县| 随州市| 西华县| 乐安县| 鲁甸县| 林芝县| 八宿县| 江都市| 北安市| 嘉兴市| 额济纳旗| 淮滨县| 东方市| 遵义县| 民乐县| 桂东县| 宜阳县| 漳州市| 惠安县| 孝感市| 乐陵市| 含山县| 东城区| 沙坪坝区| 革吉县| 紫金县|