首頁 > 後端開發 > Python教學 > python的三目运算符和not in运算符使用示例

python的三目运算符和not in运算符使用示例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-06-06 11:29:50
原創
2579 人瀏覽過

代码如下:


x = [x for x in range(1,10)]
print(x)
y =[]

result = True if 12 not in x else False  # this is  the best way
print(result)
result = True if not 12 in x else False  # this way just like as " (not 12) in x"
print(result)

print(x is y)
print(x is not y) # this is the best way
print(not x is y) # this way just like as " (not x ) is y" ,so upper is the best way

result = 2 if 1 5 else 6 # just as 1 > 2 ? 2 : 4 > 5 ? 5 : 6
print(result)

相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
javascript - 關於JS三目運算子問題
來自於 1970-01-01 08:00:00
0
0
0
三元運算符
來自於 1970-01-01 08:00:00
0
0
0
預設參數問題
來自於 1970-01-01 08:00:00
0
0
0
javascript - 三目運算子的一些問題
來自於 1970-01-01 08:00:00
0
0
0
預設參數問題
來自於 1970-01-01 08:00:00
0
0
0
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板