- 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入門很輕松(微課超值版)
- Mastering Python Scripting for System Administrators
- Django Design Patterns and Best Practices
- Hands-On Reinforcement Learning with Python
- Integrating Facebook iOS SDK with Your Application
- Java編程的邏輯
- Java程序設計案例教程
- 計算機應用技能實訓教程
- 從Excel到Python數據分析:Pandas、xlwings、openpyxl、Matplotlib的交互與應用
- 超簡單:Photoshop+JavaScript+Python智能修圖與圖像自動化處理
- 深度學習程序設計實戰
- 零基礎學C++(升級版)
- SSH框架企業級應用實戰
- Mastering SciPy
- C++面向對象程序設計教程