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

Python if...else statement syntax

In this section, we are going to learn about the if..else statement. The else block will get executed only when the if condition is false. Refer to the following syntax:

if test expression:
if block
else:
else block

The if..else statement evaluates the test expression and will execute the body of if only when the test condition is true. If the condition is false, the body of else is executed. Indentation is used to separate the blocks. Refer to the following example:

a = 10
if a > 0:
print("Positive number")
else:
print("Negative number")

Output:
Positive number
主站蜘蛛池模板: 敖汉旗| 锡林浩特市| 那曲县| 兴城市| 台山市| 屏南县| 永德县| 新余市| 布拖县| 靖安县| 万源市| 云南省| 铜鼓县| 扶沟县| 饶平县| 临高县| 弥渡县| 罗源县| 临沂市| 双柏县| 丹棱县| 大庆市| 聂荣县| 连江县| 固阳县| 长丰县| 上林县| 青岛市| 蒲江县| 获嘉县| 牙克石市| 宁海县| 九江县| 乌鲁木齐市| 保康县| 阜阳市| 汽车| 遵化市| 纳雍县| 青川县| 商南县|