-
在python中這樣規(guī)定三元運算符的使用方法:
[on true] if [expression] else [on false]
當
expression
表達式為真的時候執(zhí)行on true
代碼,當表達式為假的時候執(zhí)行on false
代碼文章來源:http://www.zghlxwxcb.cn/news/detail-517129.htmla, b = 1, 1 print(a + b if True else a-b) # 2 print(a + b if False else a-b) # 0
?
?文章來源地址http://www.zghlxwxcb.cn/news/detail-517129.html
到了這里,關(guān)于python中的三元運算符的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!