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

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.
主站蜘蛛池模板: 新乡市| 鲁甸县| 娄底市| 宁远县| 贺州市| 陆河县| 喀什市| 丹凤县| 昆山市| 筠连县| 嘉荫县| 蓬安县| 内黄县| 察隅县| 滕州市| 冕宁县| 印江| 夏津县| 治多县| 江源县| 登封市| 新泰市| 娄烦县| 久治县| 台北县| 葫芦岛市| 即墨市| 甘泉县| 施秉县| 香格里拉县| 湘阴县| 黑河市| 右玉县| 丰镇市| 旬邑县| 周宁县| 林州市| 和硕县| 河间市| 岳普湖县| 黄石市|