新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python里的if語句怎么寫

創(chuàng)新互聯(lián)建站是一家專注于成都做網(wǎng)站、成都網(wǎng)站建設(shè)與策劃設(shè)計,高唐網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:高唐等地區(qū)。高唐做網(wǎng)站價格咨詢:18980820575
if 結(jié)構(gòu)
if 結(jié)構(gòu)允許程序做出選擇,并根據(jù)不同的情況執(zhí)行不同的操作
基本用法
比較運算符
根據(jù) PEP 8 標準,比較運算符兩側(cè)應(yīng)該各有一個空格,比如:5 == 3。 PEP8 標準
==(相等):如果該運算符兩側(cè)的值完全相同則返回 True
!=(不等):與相等相反
print(5 == '5')
print(True == '1')
print(True == 1)
print('Eric'.lower() == 'eric'.lower())>(大于):左側(cè)大于右側(cè)則輸出 True
<(小于):與大于相反
>=(大于等于):左側(cè)大于或者等于右側(cè)則輸出 True
<=(小于等于):左側(cè)小于或者等于右側(cè)則輸出 True
print(5 > 3) print(2 > True) print(True > False)
if的用法
if 進行判斷
desserts = ['ice cream', 'chocolate', 'apple crisp', 'cookies']
favorite_dessert = 'apple crisp'
hate_dessert = 'chocolate'
for dessert in desserts:
if dessert == favorite_dessert:
print("%s is my favorite dessert!" % dessert.title())推薦學(xué)習(xí)《python教程》。
文章題目:創(chuàng)新互聯(lián)Python教程:python里的if語句怎么寫
網(wǎng)頁網(wǎng)址:http://fisionsoft.com.cn/article/dpehidp.html


咨詢
建站咨詢
