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

創(chuàng)新互聯(lián)建站是一家專注于成都做網站、成都網站建設與策劃設計,高唐網站建設哪家好?創(chuàng)新互聯(lián)建站做網站,專注于網站建設十載,網設計領域的專業(yè)建站公司;建站業(yè)務涵蓋:高唐等地區(qū)。高唐做網站價格咨詢:18980820575
if 結構
if 結構允許程序做出選擇,并根據(jù)不同的情況執(zhí)行不同的操作
基本用法
比較運算符
根據(jù) PEP 8 標準,比較運算符兩側應該各有一個空格,比如:5 == 3。 PEP8 標準
==(相等):如果該運算符兩側的值完全相同則返回 True
!=(不等):與相等相反
print(5 == '5')
print(True == '1')
print(True == 1)
print('Eric'.lower() == 'eric'.lower())>(大于):左側大于右側則輸出 True
<(小于):與大于相反
>=(大于等于):左側大于或者等于右側則輸出 True
<=(小于等于):左側小于或者等于右側則輸出 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())推薦學習《python教程》。
分享名稱:創(chuàng)新互聯(lián)Python教程:python里的if語句怎么寫
當前鏈接:http://m.5511xx.com/article/dpehidp.html


咨詢
建站咨詢
