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

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
主站蜘蛛池模板: 海口市| 长寿区| 南澳县| 闽侯县| 阿巴嘎旗| 津南区| 苍山县| 海林市| 惠水县| 容城县| 巩义市| 元谋县| 高清| 含山县| 浏阳市| 宜川县| 娄底市| 驻马店市| 乳源| 延边| 石河子市| 南平市| 盐亭县| 繁峙县| 田东县| 朝阳县| 新闻| 苗栗县| 贞丰县| 阿合奇县| 鸡西市| 江川县| 南汇区| 乳山市| 湛江市| 宜都市| 彭山县| 临江市| 武川县| 克什克腾旗| 霍林郭勒市|