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

Python if statement syntax

The following is the syntax for the if statement:

if test_expression:
statement(s)

Here, the program evaluates the test expression and will execute statement(s) only if the text expression is true. If the text expression is false, statement(s) isn't executed.

In Python, the body of the if statement is indicated by the indentation. The body starts with an indentation and the first unindented line marks the end. Let's look at an example:

a = 10
if a > 0:
print(a, "is a positive number.")
print("This statement is always printed.")

a = -10
if a > 0:
print(a, "is a positive number.")

Output:
10 is a positive number.
This statement is always printed.
主站蜘蛛池模板: 丰城市| 冷水江市| 朝阳区| 永川市| 瑞安市| 曲阳县| 三原县| 含山县| 阿瓦提县| 平南县| 河津市| 惠东县| 高陵县| 绥中县| 华宁县| 布拖县| 土默特左旗| 象州县| 关岭| 凌海市| 林周县| 屏东市| 龙江县| 罗山县| 金溪县| 阿尔山市| 大理市| 新营市| 安塞县| 黎平县| 古田县| 昌乐县| 诸城市| 太原市| 塔城市| 铜川市| 固始县| 连江县| 河西区| 油尖旺区| 清水县|