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

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.
主站蜘蛛池模板: 当雄县| 商河县| 息烽县| 新巴尔虎左旗| 铜川市| 洪雅县| 都昌县| 饶阳县| 靖边县| 沂源县| 三穗县| 建平县| 南昌市| 子洲县| 台中县| 龙南县| 瑞丽市| 巴林右旗| 亚东县| 兴安盟| 宝应县| 五指山市| 抚宁县| 溧水县| 来安县| 郎溪县| 铜鼓县| 习水县| 麻栗坡县| 渭源县| 墨玉县| 嘉黎县| 黔江区| 洪江市| 安顺市| 淅川县| 新密市| 北票市| 聂荣县| 唐河县| 平顺县|