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

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
主站蜘蛛池模板: 凤山县| 融水| 右玉县| 普兰店市| 鄯善县| 澄迈县| 阿拉尔市| 榕江县| 四平市| 台前县| 尖扎县| 天水市| 沙河市| 梁平县| 吉安市| 开封县| 屏南县| 梁山县| 汤阴县| 北票市| 华宁县| 河东区| 蒲江县| 柏乡县| 广州市| 旺苍县| 高要市| 瑞安市| 托里县| 南丹县| 江油市| 台山市| 东台市| 扬州市| 梁平县| 五峰| 龙州县| 枣强县| 通道| 龙海市| 云霄县|