單項選擇題在Python中,如何使用條件表達式(三元運算符)?()

A.x if condition else y
B.condition ?x :y
C.if condition:x else:y
D.condition then x else y


您可能感興趣的試卷

你可能感興趣的試題

1.單項選擇題在Python中,如何檢查一個文件是否存在?()

A.os.path.exists(path)
B.file.exists(path)
C.path.exists(file)
D.os.exists(file)

2.單項選擇題在Python中,如何判斷一個字符串是否以某個子字符串結束?()

A.str.endswith(substring)
B.endswith(str,substring)
C.str.hasSuffix(substring)

3.單項選擇題在Python中,如何判斷一個字符串是否以某個子字符串開始?()

A.str.startswith(substring)
B.str.beginswith(substring)
C.str.hasPrefix(substring)
D.startswith(str,substring)

4.單項選擇題在Python中,如何測試一個條件,并根據結果執(zhí)行不同的代碼塊?()

A.if condition:pass else:pass
B.test condition then pass else pass
C.if condition:pass elseif:pass
D.condition ?pass :pass

5.單項選擇題在Python中,如何創(chuàng)建一個Lambda函數?()

A.lambda x:x +1
B.(x)=>x +1
C.function(x)x +1
D.def(x):x +1