學習筆記 Python條件判斷 If語句

2021-08-13 05:47:22 字數 701 閱讀 4319

例項**

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

# tuple的使用

# if語句

print('請輸入數字')

# 型別轉換,不然會報錯

age = int(input())

if age == 18:

print('%d == %d' %(age, 18))

elif age > 18:

print('%d > %d' %(age, 18))

else:

print('%d < %d' %(age, 18))

執行結果

d:\pythonproject>python run.py

請輸入數字

7878 > 18

d:\pythonproject>python run.py

請輸入數字

1818 == 18

d:\pythonproject>python run.py

請輸入數字88

< 18

冒號收尾,就是格式稍微變化,理解還是ok

if x:

***x

elif y:

***else z:

***

python學習筆記 條件判斷

上篇 條件判斷是通過一條或多條判斷語句的執行結果 true或者false 來決定執行的 塊。在python語法中,使用if elif和else三個關鍵字來進行條件判斷。if語句的一般形式如下所示 if condition1 condition1為true 執行statement block 1 st...

SHELL學習筆記 IF條件判斷,判斷條件

前言 無論什麼程式語言都離不開條件判斷。shell也不例外。if list then do something here elif list then do another thing here else do something else here fi ex1 bin sh system una...

SHELL學習筆記 IF條件判斷,判斷條件

前言 無論什麼程式語言都離不開條件判斷。shell也不例外。if list then do something here elif list then do another thing here else do something else here fi ex1 bin sh system una...