python基礎之條件表示式

2021-10-09 22:59:29 字數 1131 閱讀 1473

#分支語句

score=

98if score>=90:

print

('優秀'

)elif score>=80:

print

('不錯'

)elif score>=60:

print

('及格'

)else

:print

('不及格')a=

input

('請輸入乙個數字:'

)#input()函式,從鍵盤讀取使用者的輸入,a是返回值,是字串型別

ifnot a.isdigit():

#判斷輸入的是否是數字

print

('您輸入的不是純數字'

)else

:print

('您輸入的是純數字,可以進行運算'

)print

('您輸入的數字的平方是:'

+str

(int

(a)**2)

)#字串的拼接,必須都是字串

#多重分支

age=

62gender=

'女'if age>=60:

if gender==

'男':

print

('老先生'

)#年齡大於等於60歲,並且為男性,稱之為老先生

if age>=

60and gender==

'男':

#年齡大於等於60歲,並且為男性,稱之為老先生

print

('老先生')if

1:#只要不是0或者false或者''或者none,其他都為真

print

('hello')if

""or0or

false

ornone

:print

('world'

)

列印結果演示

優秀

請輸入乙個數字:

67您輸入的是純數字,可以進行運算

您輸入的數字的平方是:

4489

hello

process finished with exit code 0

Python 條件表示式

import os import re mask re.compile fna 說明從後開始匹配 最好先看一下當前路徑是什麼 os.getcwd 獲得資料夾裡面所以檔名 file names os.listdir 或者隨便用個例子 file names 1.fna 1.fna.nsq 1.fna.n...

Oracle SQL 之條件表示式

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!在oracle中,我們有兩種方式可以實現if then else的邏輯 case 語句 或者 decode 函式 相比較來說decode 函式會更加的簡潔。我們在oracle資料庫中建立乙個user info表 create table user ...

python 條件表示式學習

與 and 或 or 非 not rfind 用法 返回值是查詢到的目標字元在原字串中的下標,如果沒找到返回 1,如果在第0個位置找到返回0,其他的數字。錯誤例項 rule suffix ls rule.rfind pre 1not rule.rfind pre false rule.rfind p...