- Mastering Python Scripting for System Administrators
- Ganesh Sanjiv Naik
- 102字
- 2021-07-02 14:00:27
Python if...else statement syntax
In this section, we are going to learn about the if..else statement. The else block will get executed only when the if condition is false. Refer to the following syntax:
if test expression:
if block
else:
else block
The if..else statement evaluates the test expression and will execute the body of if only when the test condition is true. If the condition is false, the body of else is executed. Indentation is used to separate the blocks. Refer to the following example:
a = 10
if a > 0:
print("Positive number")
else:
print("Negative number")
Output:
Positive number
推薦閱讀
- Learning LibGDX Game Development(Second Edition)
- 玩轉(zhuǎn)Scratch少兒趣味編程
- Visual Basic .NET程序設(shè)計(jì)(第3版)
- JavaScript從入門(mén)到精通(微視頻精編版)
- Python快樂(lè)編程:人工智能深度學(xué)習(xí)基礎(chǔ)
- 體驗(yàn)設(shè)計(jì)原理:行為、情感和細(xì)節(jié)
- Developing Middleware in Java EE 8
- FreeSWITCH 1.6 Cookbook
- Java技術(shù)手冊(cè)(原書(shū)第7版)
- Julia機(jī)器學(xué)習(xí)核心編程:人人可用的高性能科學(xué)計(jì)算
- 網(wǎng)絡(luò)爬蟲(chóng)原理與實(shí)踐:基于C#語(yǔ)言
- 你不知道的JavaScript(中卷)
- 軟件測(cè)試實(shí)用教程
- 零基礎(chǔ)看圖學(xué)ScratchJr:少兒趣味編程(全彩大字版)
- Mastering OAuth 2.0