- 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.
推薦閱讀
- Mastering NetBeans
- Java范例大全
- Visual Studio 2012 Cookbook
- 算法精粹:經(jīng)典計算機(jī)科學(xué)問題的Python實現(xiàn)
- Visual Foxpro 9.0數(shù)據(jù)庫程序設(shè)計教程
- 并行編程方法與優(yōu)化實踐
- 從0到1:HTML5 Canvas動畫開發(fā)
- OpenCV with Python Blueprints
- 交互式程序設(shè)計(第2版)
- ASP.NET 4.0 Web程序設(shè)計
- Python 快速入門(第3版)
- C/C++代碼調(diào)試的藝術(shù)(第2版)
- 3D Printing Designs:The Sun Puzzle
- 算法超簡單:趣味游戲帶你輕松入門與實踐
- Mastering Clojure