- Mastering Python Scripting for System Administrators
- Ganesh Sanjiv Naik
- 115字
- 2021-07-02 14:00:27
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.
推薦閱讀
- Java逍遙游記
- C++程序設計教程
- Bootstrap Site Blueprints Volume II
- SoapUI Cookbook
- Learning Apex Programming
- JavaScript+DHTML語法與范例詳解詞典
- JMeter 性能測試實戰(第2版)
- 物聯網系統開發:從0到1構建IoT平臺(第2版)
- Python神經網絡項目實戰
- Spring實戰(第5版)
- MySQL數據庫基礎實例教程(微課版)
- Kotlin開發教程(全2冊)
- Access 2010中文版項目教程
- Python GUI Programming Cookbook(Second Edition)
- 第五空間戰略:大國間的網絡博弈